os-cmpi-xen

changeset 125:ce72210a88c6

Port Xen_ProcessorSettingData to new 'cmpilr' instance interface.

While porting Xen_ProcessorSettingData and implementing its modify()
function, realized the the 'cmpilr' interface was overloading parameters
to get() and modify(). The issue was raised with Gareth (and sblim-devel)
and it was agreed to add another parameter to these functions. The
interface was changed locally (and hence providers using it had to change)
and will need to be synched with sblim 'cmpilify' project cvs at some point.
We will keep the local copy until churn of the interface settles - at which
time the local copy will be updated and (probably) all providers using the
interface will have to be updated as well.

Signed-off-by: Jim Fehlig <jfehlig@novell.com>
author Jim Fehlig <jfehlig@novell.com>
date Tue Jun 12 17:44:58 2007 -0600 (2007-06-12)
parents 7d3fcd10080c
children d1dab4776fed
files src/Makefile.am src/Xen_Disk.c src/Xen_DiskSettingData.c src/Xen_Processor.c src/Xen_ProcessorSettingData.c src/Xen_VirtualSystemManagementCapabilities.c src/cmpilr.c src/cmpilr.h
line diff
     1.1 --- a/src/Makefile.am	Mon Jun 11 15:38:51 2007 -0600
     1.2 +++ b/src/Makefile.am	Tue Jun 12 17:44:58 2007 -0600
     1.3 @@ -53,7 +53,6 @@ noinst_HEADERS = \
     1.4  	Xen_Console_Resource.h \
     1.5  	Xen_VirtualizationCapabilities_Resource.h \
     1.6  	Xen_ComputerSystemSettingData_Resource.h \
     1.7 -	Xen_ProcessorSettingData_Resource.h \
     1.8  	Xen_MemorySettingData_Resource.h \
     1.9  	Xen_NetworkPortSettingData_Resource.h \
    1.10  	Xen_ConsoleSettingData_Resource.h \
    1.11 @@ -240,7 +239,7 @@ libXen_CSElementSettingData_la_SOURCES =
    1.12  libXen_CSElementSettingData_la_LIBADD = libXen_ProviderCommon.la
    1.13  libXen_CSElementSettingData_la_LDFLAGS = -module -avoid-version -no-undefined
    1.14  
    1.15 -libXen_ProcessorSettingData_la_SOURCES = Xen_ProcessorSettingData.c Xen_ProcessorSettingData_Resource.c
    1.16 +libXen_ProcessorSettingData_la_SOURCES = Xen_ProcessorSettingData.c
    1.17  libXen_ProcessorSettingData_la_CFLAGS = -I../ @LIBXEN_CFLAGS@
    1.18  libXen_ProcessorSettingData_la_LIBADD = libXen_ProviderCommon.la
    1.19  libXen_ProcessorSettingData_la_LDFLAGS = -module -avoid-version -no-undefined
     2.1 --- a/src/Xen_Disk.c	Mon Jun 11 15:38:51 2007 -0600
     2.2 +++ b/src/Xen_Disk.c	Tue Jun 12 17:44:58 2007 -0600
     2.3 @@ -71,10 +71,8 @@ static int load()
     2.4  }
     2.5  
     2.6  
     2.7 -static int unload(CMPIBoolean terminating)
     2.8 +static int unload()
     2.9  {
    2.10 -   (void) terminating;
    2.11 -   
    2.12     if (session) {
    2.13        xen_utils_xen_close(session);
    2.14        session = NULL;
    2.15 @@ -84,6 +82,13 @@ static int unload(CMPIBoolean terminatin
    2.16  }
    2.17  
    2.18  
    2.19 +/*
    2.20 + * beginEnum is called before any function that uses the xen session.
    2.21 + * In the event this provider is loaded but has not been invoked for some
    2.22 + * time, the xen session object will be validated in beginEnum.  Functions
    2.23 + * called directly after beginEnum (e.g. get, getNext, modify) should
    2.24 + * set the session 'ok' flag.
    2.25 + */
    2.26  static int beginEnum(void **res_list, CMPIStatus *status)
    2.27  {
    2.28     _RESOURCES *resources;
    2.29 @@ -178,15 +183,8 @@ static int getNext(void *res_list, void 
    2.30     if (resources->currentdisknum == resources->disks->size)
    2.31        return 0;
    2.32  
    2.33 -   if (!xen_utils_validate_session(&session)) {
    2.34 -      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
    2.35 -                   ("--- Unable to establish connection with Xend"));
    2.36 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
    2.37 -                           "Unable to establish connection with Xend");
    2.38 -      return 0;
    2.39 -   }
    2.40 -
    2.41     /* Get the current disk record. */
    2.42 +   session->xen->ok = true;
    2.43     if (!xen_vbd_get_record(session->xen, &vbd_rec,
    2.44                             resources->disks->contents[resources->currentdisknum])) {
    2.45        _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
    2.46 @@ -204,16 +202,66 @@ static int getNext(void *res_list, void 
    2.47  }
    2.48  
    2.49  
    2.50 -static int get(void *res_list, void **res, CMPIStatus *status)
    2.51 +static int get(void *res_list, const CMPIObjectPath *op,
    2.52 +               void **res, CMPIStatus *status)
    2.53  {
    2.54 -   if (res == NULL || *res == NULL)
    2.55 +   CMPIData data;
    2.56 +   char *dev_uuid;
    2.57 +   int ccode;
    2.58 +
    2.59 +   (void)res_list;
    2.60 +   
    2.61 +   if (CMIsNullObject(op) || res == NULL)
    2.62 +      return 0;
    2.63 +
    2.64 +   data = CMGetKey(op, "DeviceID", status);
    2.65 +   if ((status->rc != CMPI_RC_OK) || CMIsNullValue(data))
    2.66 +      return 0;
    2.67 +
    2.68 +   /* Extract the domain name string from the CMPIString. */
    2.69 +   dev_uuid = CMGetCharPtr(data.value.string);
    2.70 +   if ((dev_uuid == NULL) || (*dev_uuid == '\0'))
    2.71        return 0;
    2.72 -   /*
    2.73 -    * WARNING!
    2.74 -    * What needs to be done here?  It looks as though inst2res() will have
    2.75 -    * been called on parameter res before a call to this function - in
    2.76 -    * which case res will be populated.
    2.77 +
    2.78 +   session->xen->ok = true;
    2.79 +
    2.80 +   xen_vbd_record *vbd_rec;
    2.81 +   if (!xen_vbd_get_record(session->xen, &vbd_rec, (xen_vbd)dev_uuid)) {
    2.82 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
    2.83 +                   ("--- xen_vbd_get_record failed:"));
    2.84 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
    2.85 +                            xen_utils_trace_error(session->xen));
    2.86 +      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
    2.87 +                           "xen_vbd_get_record failed");
    2.88 +      return 0;
    2.89 +   }
    2.90 +
    2.91 +   /* TODO:
    2.92 +    * For now Xen_Disk instances only exist when domain is not inactive,
    2.93 +    * so return NOT_FOUND.
    2.94 +    * Should disks be one of the few logical devices that do exist even
    2.95 +    * when domain is inactive?
    2.96      */
    2.97 +   enum xen_vm_power_state pstate;
    2.98 +   if (!xen_vm_get_power_state(session->xen, &pstate, vbd_rec->vm->u.handle)) {
    2.99 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   2.100 +                   ("--- xen_vm_get_power_state failed:"));
   2.101 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   2.102 +                            xen_utils_trace_error(session->xen));
   2.103 +      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   2.104 +                           "Unable to determine vm power state");
   2.105 +      xen_vbd_record_free(vbd_rec);
   2.106 +      
   2.107 +      return 0;
   2.108 +   }
   2.109 +
   2.110 +   if (pstate == XEN_VM_POWER_STATE_HALTED) {
   2.111 +         CMSetStatus(status, CMPI_RC_ERR_NOT_FOUND);
   2.112 +         xen_vbd_record_free(vbd_rec);
   2.113 +         return 0;
   2.114 +   }
   2.115 +   
   2.116 +   *res = (void *)vbd_rec;
   2.117     return 1;
   2.118  }
   2.119  
   2.120 @@ -226,34 +274,7 @@ static void release(void *res)
   2.121  
   2.122  static int add(void **res_list, void *res, CMPIStatus *status)
   2.123  {
   2.124 -   xen_vbd_record *new_vbd_rec = (xen_vbd_record *)res;
   2.125 -   
   2.126 -   (void)res_list;
   2.127 -   
   2.128 -   if (new_vbd_rec == NULL || new_vbd_rec->vm == NULL)
   2.129 -      return 0;
   2.130 -   
   2.131 -   if (!xen_utils_validate_session(&session)) {
   2.132 -      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   2.133 -                   ("--- Unable to establish connection with Xend"));
   2.134 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   2.135 -                           "Unable to establish connection with Xend");
   2.136 -      return 0;
   2.137 -   }
   2.138 -
   2.139 -   xen_vbd new_vbd;
   2.140 -   if (!xen_vbd_create(session->xen, &new_vbd, new_vbd_rec)) {
   2.141 -      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   2.142 -                   ("--- xen_vbd_create failed:"));
   2.143 -      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   2.144 -                            xen_utils_trace_error(session->xen));
   2.145 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   2.146 -                           "xen_vbd_create failed");
   2.147 -      return 0;
   2.148 -   }
   2.149 -
   2.150 -   xen_vbd_free(new_vbd);
   2.151 -   return 1;
   2.152 +   return -1; /* unsupported */
   2.153  }
   2.154  
   2.155  
   2.156 @@ -266,14 +287,7 @@ static int delete(void **res_list, void 
   2.157     if (vbd_rec == NULL)
   2.158        return 0;
   2.159     
   2.160 -   if (!xen_utils_validate_session(&session)) {
   2.161 -      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   2.162 -                   ("--- Unable to establish connection with Xend"));
   2.163 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   2.164 -                           "Unable to establish connection with Xend");
   2.165 -      return 0;
   2.166 -   }
   2.167 -
   2.168 +   session->xen->ok = true;
   2.169     if (!xen_vbd_destroy(session->xen, vbd_rec->handle)) {
   2.170        _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   2.171                     ("--- xen_vbd_create failed:"));
   2.172 @@ -288,7 +302,8 @@ static int delete(void **res_list, void 
   2.173  }
   2.174  
   2.175  
   2.176 -static int modify(void **res_list, void *res, CMPIStatus *status)
   2.177 +static int modify(void **res_list, void *target_res,
   2.178 +                  void *modified_res, CMPIStatus *status)
   2.179  {
   2.180     return -1; /* unsupported */
   2.181  }
   2.182 @@ -305,13 +320,7 @@ static int res2inst(void *res, CMPIInsta
   2.183     if (vbd_rec == NULL || CMIsNullObject(inst))
   2.184        return 0;
   2.185  
   2.186 -   if (!xen_utils_validate_session(&session)) {
   2.187 -      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   2.188 -                   ("--- Unable to establish connection with Xend"));
   2.189 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   2.190 -                           "Unable to establish connection with Xend");
   2.191 -      return 0;
   2.192 -   }
   2.193 +   session->xen->ok = true;
   2.194  
   2.195     xen_vm_record_opt *vm_rec_opt = vbd_rec->vm;
   2.196     if (vm_rec_opt->is_record) {
   2.197 @@ -390,71 +399,13 @@ static int res2inst(void *res, CMPIInsta
   2.198  }
   2.199  
   2.200  
   2.201 -/* Set resource data from the CMPIInstance properties. */ 
   2.202 +/*
   2.203 + * Set resource data from the CMPIInstance properties.  Only needs to
   2.204 + * be implemented if add() and/or modify() are supported.
   2.205 + */
   2.206  static int inst2res(CMPIInstance *inst, void **res, CMPIStatus *status)
   2.207  {
   2.208 -   CMPIData data;
   2.209 -   char *dev_uuid;
   2.210 -   char uuid[MAX_SYSTEM_NAME_LEN];
   2.211 -   int ccode;
   2.212 -
   2.213 -   if (CMIsNullObject(inst) || res == NULL)
   2.214 -      return 0;
   2.215 -
   2.216 -   data = CMGetProperty(inst, "DeviceID", status);
   2.217 -   if ((status->rc != CMPI_RC_OK) || CMIsNullValue(data))
   2.218 -      return 0;
   2.219 -
   2.220 -   dev_uuid = CMGetCharPtr(data.value.string);
   2.221 -   if ((dev_uuid == NULL) || (*dev_uuid == '\0'))
   2.222 -      return 0;
   2.223 -
   2.224 -   if (!xen_utils_validate_session(&session)) {
   2.225 -      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   2.226 -                   ("--- Unable to establish connection with Xend"));
   2.227 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   2.228 -                           "Unable to establish connection with Xend");
   2.229 -      return 0;
   2.230 -   }
   2.231 -
   2.232 -   xen_vbd_record *vbd_rec;
   2.233 -   if (!xen_vbd_get_record(session->xen, &vbd_rec, (xen_vbd)dev_uuid)) {
   2.234 -      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   2.235 -                   ("--- xen_vbd_get_record failed:"));
   2.236 -      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   2.237 -                            xen_utils_trace_error(session->xen));
   2.238 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   2.239 -                           "xen_vbd_get_record failed");
   2.240 -      return 0;
   2.241 -   }
   2.242 -
   2.243 -   /* TODO:
   2.244 -    * For now Xen_Disk instances only exist when domain is not inactive,
   2.245 -    * so return NOT_FOUND.
   2.246 -    * Should disks be one of the few logical devices that do exist even
   2.247 -    * when domain is inactive?
   2.248 -    */
   2.249 -   enum xen_vm_power_state pstate;
   2.250 -   if (!xen_vm_get_power_state(session->xen, &pstate, vbd_rec->vm->u.handle)) {
   2.251 -      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   2.252 -                   ("--- xen_vm_get_power_state failed:"));
   2.253 -      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   2.254 -                            xen_utils_trace_error(session->xen));
   2.255 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   2.256 -                           "Unable to determine vm power state");
   2.257 -      xen_vbd_record_free(vbd_rec);
   2.258 -      
   2.259 -      return 0;
   2.260 -   }
   2.261 -
   2.262 -   if (pstate == XEN_VM_POWER_STATE_HALTED) {
   2.263 -         CMSetStatus(status, CMPI_RC_ERR_NOT_FOUND);
   2.264 -         xen_vbd_record_free(vbd_rec);
   2.265 -         return 0;
   2.266 -   }
   2.267 -   
   2.268 -   *res = (void *)vbd_rec;
   2.269 -   return 1;
   2.270 +   return -1;  /* unsupported */
   2.271  }
   2.272  
   2.273  
     3.1 --- a/src/Xen_DiskSettingData.c	Mon Jun 11 15:38:51 2007 -0600
     3.2 +++ b/src/Xen_DiskSettingData.c	Tue Jun 12 17:44:58 2007 -0600
     3.3 @@ -48,6 +48,17 @@ static const CMPIInstanceMI* mi;
     3.4  #include "provider_common.h"
     3.5  
     3.6  
     3.7 +/* C struct to store the data for a single resource. */
     3.8 +typedef struct {
     3.9 +   int is_vbd_record;
    3.10 +   union
    3.11 +   {
    3.12 +      xen_vbd_record *vbd_rec;
    3.13 +      CMPIInstance *cmpi_inst;
    3.14 +   } u;
    3.15 +} _RESOURCE;
    3.16 +
    3.17 +
    3.18  /* C struct to store the data for all resources. */
    3.19  typedef struct {
    3.20     xen_vbd_set *disks;
    3.21 @@ -70,10 +81,8 @@ static int load()
    3.22  }
    3.23  
    3.24  
    3.25 -static int unload(CMPIBoolean terminating)
    3.26 +static int unload()
    3.27  {
    3.28 -   (void) terminating;
    3.29 -   
    3.30     if (session) {
    3.31        xen_utils_xen_close(session);
    3.32        session = NULL;
    3.33 @@ -83,6 +92,13 @@ static int unload(CMPIBoolean terminatin
    3.34  }
    3.35  
    3.36  
    3.37 +/*
    3.38 + * beginEnum is called before any function that uses the xen session.
    3.39 + * In the event this provider is loaded but has not been invoked for some
    3.40 + * time, the xen session object will be validated in beginEnum.  Functions
    3.41 + * called directly after beginEnum (e.g. get, getNext, modify) should
    3.42 + * set the session 'ok' flag.
    3.43 + */
    3.44  static int beginEnum(void **res_list, CMPIStatus *status)
    3.45  {
    3.46     _RESOURCES *resources;
    3.47 @@ -157,6 +173,8 @@ static void endEnum(void *res_list)
    3.48  static int getNext(void *res_list, void **res, CMPIStatus *status)
    3.49  {
    3.50     _RESOURCES *resources = (_RESOURCES *)res_list;
    3.51 +   _RESOURCE *resource;
    3.52 +
    3.53     xen_vbd_record *vbd_rec;
    3.54  
    3.55     if (resources == NULL || resources->disks == NULL)
    3.56 @@ -166,16 +184,16 @@ static int getNext(void *res_list, void 
    3.57     if (resources->currentdisknum == resources->disks->size)
    3.58        return 0;
    3.59  
    3.60 -   if (!xen_utils_validate_session(&session)) {
    3.61 -      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
    3.62 -                   ("--- Unable to establish connection with Xend"));
    3.63 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
    3.64 -                           "Unable to establish connection with Xend");
    3.65 +   /* Get memory for resource. */
    3.66 +   resource = (_RESOURCE *)calloc(1, sizeof(_RESOURCE));
    3.67 +   if (resource == NULL)
    3.68        return 0;
    3.69 -   }
    3.70 +
    3.71 +   resource->is_vbd_record = 1;
    3.72  
    3.73     /* Get the current disk record. */
    3.74 -   if (!xen_vbd_get_record(session->xen, &vbd_rec,
    3.75 +   session->xen->ok = true;
    3.76 +   if (!xen_vbd_get_record(session->xen, &(resource->u.vbd_rec),
    3.77                             resources->disks->contents[resources->currentdisknum])) {
    3.78        _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
    3.79                     ("--- failed to retrieve vbd resource from Xend:"));
    3.80 @@ -187,81 +205,86 @@ static int getNext(void *res_list, void 
    3.81     }
    3.82     
    3.83     resources->currentdisknum++;
    3.84 -   *res = (void *)vbd_rec;
    3.85 +   *res = (void *)resource;
    3.86     return 1;
    3.87  }
    3.88  
    3.89  
    3.90 -static int get(void *res_list, void **res, CMPIStatus *status)
    3.91 +static int get(void *res_list, const CMPIObjectPath *op,
    3.92 +               void **res, CMPIStatus *status)
    3.93  {
    3.94 -   if (res == NULL || *res == NULL)
    3.95 +   CMPIData data;
    3.96 +   char *inst_id;
    3.97 +   char uuid[MAX_SYSTEM_NAME_LEN];
    3.98 +   _RESOURCE *resource;
    3.99 +
   3.100 +   (void)res_list;
   3.101 +
   3.102 +   if (CMIsNullObject(op) || res == NULL)
   3.103 +      return 0;
   3.104 +
   3.105 +   data = CMGetKey(op, "InstanceID", status);
   3.106 +   if ((status->rc != CMPI_RC_OK) || CMIsNullValue(data))
   3.107 +      return 0;
   3.108 +
   3.109 +   inst_id = CMGetCharPtr(data.value.string);
   3.110 +   if ((inst_id == NULL) || (*inst_id == '\0'))
   3.111        return 0;
   3.112 -   /*
   3.113 -    * WARNING!
   3.114 -    * What needs to be done here?  It looks as though inst2res() will have
   3.115 -    * been called on parameter res before a call to this function - in
   3.116 -    * which case res will be populated.
   3.117 -    */
   3.118 +
   3.119 +   /* Extract the disk uuid from InstanceID property. */
   3.120 +   if (!_CMPIStrncpyDeviceNameFromID(uuid, inst_id, MAX_SYSTEM_NAME_LEN))
   3.121 +      return 0;
   3.122 +
   3.123 +   /* Get memory for resource. */
   3.124 +   resource = (_RESOURCE *)calloc(1, sizeof(_RESOURCE));
   3.125 +   if (resource == NULL)
   3.126 +      return 0;
   3.127 +
   3.128 +   resource->is_vbd_record = 1;
   3.129 +
   3.130 +   session->xen->ok = true;
   3.131 +   if (!xen_vbd_get_record(session->xen, &(resource->u.vbd_rec), (xen_vbd)uuid)) {
   3.132 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.133 +                   ("--- xen_vbd_get_record failed:"));
   3.134 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   3.135 +                            xen_utils_trace_error(session->xen));
   3.136 +      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   3.137 +                           "xen_vbd_get_record failed");
   3.138 +      return 0;
   3.139 +   }
   3.140 +
   3.141 +   *res = (void *)resource;
   3.142     return 1;
   3.143  }
   3.144  
   3.145  
   3.146  static void release(void *res)
   3.147  {
   3.148 -   xen_vbd_record_free(res);
   3.149 +   if (res) {
   3.150 +      _RESOURCE *resource = (_RESOURCE *)res;
   3.151 +      if (resource->is_vbd_record)
   3.152 +         xen_vbd_record_free(resource->u.vbd_rec);
   3.153 +      free(resource);
   3.154 +   }
   3.155  }
   3.156  
   3.157  
   3.158  static int add(void **res_list, void *res, CMPIStatus *status)
   3.159  {
   3.160 -   xen_vbd_record *new_vbd_rec = (xen_vbd_record *)res;
   3.161 -   
   3.162 -   (void)res_list;
   3.163 -   
   3.164 -   if (new_vbd_rec == NULL || new_vbd_rec->vm == NULL)
   3.165 -      return 0;
   3.166 -   
   3.167 -   if (!xen_utils_validate_session(&session)) {
   3.168 -      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.169 -                   ("--- Unable to establish connection with Xend"));
   3.170 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   3.171 -                           "Unable to establish connection with Xend");
   3.172 -      return 0;
   3.173 -   }
   3.174 -
   3.175 -   xen_vbd new_vbd;
   3.176 -   if (!xen_vbd_create(session->xen, &new_vbd, new_vbd_rec)) {
   3.177 -      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.178 -                   ("--- xen_vbd_create failed:"));
   3.179 -      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   3.180 -                            xen_utils_trace_error(session->xen));
   3.181 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   3.182 -                           "xen_vbd_create failed");
   3.183 -      return 0;
   3.184 -   }
   3.185 -
   3.186 -   xen_vbd_free(new_vbd);
   3.187 -   return 1;
   3.188 +   return -1; /* unsupported */
   3.189  }
   3.190  
   3.191  
   3.192  static int delete(void **res_list, void *res, CMPIStatus *status)
   3.193  {
   3.194 -   xen_vbd_record *vbd_rec = (xen_vbd_record *)res;
   3.195 -   
   3.196     (void)res_list;
   3.197     
   3.198 -   if (vbd_rec == NULL)
   3.199 +   if (res == NULL || !(((_RESOURCE *)res)->is_vbd_record))
   3.200        return 0;
   3.201     
   3.202 -   if (!xen_utils_validate_session(&session)) {
   3.203 -      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.204 -                   ("--- Unable to establish connection with Xend"));
   3.205 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   3.206 -                           "Unable to establish connection with Xend");
   3.207 -      return 0;
   3.208 -   }
   3.209 -
   3.210 +   xen_vbd_record *vbd_rec = ((_RESOURCE *)res)->u.vbd_rec;
   3.211 +   
   3.212 +   session->xen->ok = true;
   3.213     if (!xen_vbd_destroy(session->xen, vbd_rec->handle)) {
   3.214        _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.215                     ("--- xen_vbd_destroy failed:"));
   3.216 @@ -276,28 +299,116 @@ static int delete(void **res_list, void 
   3.217  }
   3.218  
   3.219  
   3.220 -static int modify(void **res_list, void *res, CMPIStatus *status)
   3.221 +static int modify(void **res_list, void *target_res,
   3.222 +                  void *modified_res, CMPIStatus *status)
   3.223  {
   3.224 -   return -1; /* unsupported */
   3.225 +   CMPIInstance *cmpi_inst;
   3.226 +   xen_vbd_record *vbd_rec;
   3.227 +   CMPIData data;
   3.228 +   char buf[64];
   3.229 +
   3.230 +   if (target_res == NULL || modified_res == NULL)
   3.231 +      return 0;
   3.232 +
   3.233 +   session->xen->ok = true;
   3.234 +   
   3.235 +   cmpi_inst = ((_RESOURCE *)modified_res)->u.cmpi_inst;
   3.236 +   vbd_rec = ((_RESOURCE *)target_res)->u.vbd_rec;
   3.237 +
   3.238 +   /* For now, allow modifying Mode only */
   3.239 +   data = CMGetProperty(cmpi_inst, "DiskConfigInfo", status);
   3.240 +   if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(data)) {
   3.241 +      /*
   3.242 +       * Extract mode from the DiskConfigInfo string.  Format is
   3.243 +       * uname,dev,mode,<backend>
   3.244 +       */
   3.245 +      char *tmp_str = NULL;
   3.246 +      char *tok;
   3.247 +      char *next_tok;
   3.248 +      tmp_str = strdup(CMGetCharPtr(data.value.string));
   3.249 +
   3.250 +      /* 
   3.251 +       * Not doing anything with the first 2 tokens now, but we'll have them
   3.252 +       * ready to go
   3.253 +       */
   3.254 +      tok = strtok_r(tmp_str, ",", &next_tok);
   3.255 +      if (tok == NULL) {
   3.256 +         _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.257 +                      ("--- Malformed DiskConfigInfo property"));
   3.258 +         CMSetStatusWithChars(_BROKER, status,
   3.259 +                              CMPI_RC_ERR_FAILED,
   3.260 +                              "Malformed DickConfigInfo property");
   3.261 +         free(tmp_str);
   3.262 +         return 0;
   3.263 +      }
   3.264 +
   3.265 +      tok = strtok_r(NULL, ",", &next_tok);
   3.266 +      if (tok == NULL) {
   3.267 +         _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.268 +                      ("--- Malformed DiskConfigInfo property"));
   3.269 +         CMSetStatusWithChars(_BROKER, status,
   3.270 +                              CMPI_RC_ERR_FAILED,
   3.271 +                              "Malformed DickConfigInfo property");
   3.272 +         free(tmp_str);
   3.273 +         return 0;
   3.274 +      }
   3.275 +
   3.276 +      tok = strtok_r(NULL, ",", &next_tok);
   3.277 +      if (tok == NULL) {
   3.278 +         _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.279 +                      ("--- Malformed DiskConfigInfo property"));
   3.280 +         CMSetStatusWithChars(_BROKER, status,
   3.281 +                              CMPI_RC_ERR_FAILED,
   3.282 +                              "Malformed DickConfigInfo property");
   3.283 +         free(tmp_str);
   3.284 +         return 0;
   3.285 +      }
   3.286 +
   3.287 +      if ((strcmp(tok, "w") == 0)  && (vbd_rec->mode == XEN_VBD_MODE_RO)) {
   3.288 +         if (!xen_vbd_set_mode(session->xen, vbd_rec->handle, XEN_VBD_MODE_RW)) {
   3.289 +            _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.290 +                         ("--- xen_vbd_set_mode failed:"));
   3.291 +            _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   3.292 +                                  xen_utils_trace_error(session->xen));
   3.293 +            CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   3.294 +                                 "xen_vbd_set_mode failed");
   3.295 +            free(tmp_str);
   3.296 +            return 0;
   3.297 +         }
   3.298 +      }
   3.299 +      else if ((strcmp(tok, "r") == 0)  && (vbd_rec->mode == XEN_VBD_MODE_RW)) {
   3.300 +         if (!xen_vbd_set_mode(session->xen, vbd_rec->handle, XEN_VBD_MODE_RO)) {
   3.301 +            _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.302 +                         ("--- xen_vbd_set_mode failed:"));
   3.303 +            _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   3.304 +                                  xen_utils_trace_error(session->xen));
   3.305 +            CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   3.306 +                                 "xen_vbd_set_mode failed");
   3.307 +            free(tmp_str);
   3.308 +            return 0;
   3.309 +         }
   3.310 +      }
   3.311 +      free(tmp_str);
   3.312 +   }
   3.313 +
   3.314 +   return 1;
   3.315  }
   3.316  
   3.317  
   3.318  /* Set CMPIInstance properties from the resource data. */
   3.319  static int res2inst(void *res, CMPIInstance *inst, CMPIStatus *status)
   3.320  {
   3.321 -   xen_vbd_record *vbd_rec = (xen_vbd_record *)res;
   3.322 +   xen_vbd_record *vbd_rec;
   3.323     char buf[MAX_INSTANCEID_LEN];
   3.324     
   3.325 -   if (vbd_rec == NULL || CMIsNullObject(inst))
   3.326 +   if (res == NULL || CMIsNullObject(inst))
   3.327        return 0;
   3.328  
   3.329 -   if (!xen_utils_validate_session(&session)) {
   3.330 -      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.331 -                   ("--- Unable to establish connection with Xend"));
   3.332 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   3.333 -                           "Unable to establish connection with Xend");
   3.334 +   if (!(((_RESOURCE *)res)->is_vbd_record))
   3.335        return 0;
   3.336 -   }
   3.337 +   
   3.338 +   session->xen->ok = true;
   3.339 +   vbd_rec = ((_RESOURCE *)res)->u.vbd_rec;
   3.340  
   3.341     xen_vm_record_opt *vm_rec_opt = vbd_rec->vm;
   3.342     if (vm_rec_opt->is_record) {
   3.343 @@ -371,48 +482,22 @@ static int res2inst(void *res, CMPIInsta
   3.344  }
   3.345  
   3.346  
   3.347 -/* Set resource data from the CMPIInstance properties. */ 
   3.348 +/*
   3.349 + * Set resource data from the CMPIInstance properties.  Only needs to
   3.350 + * be implemented if add() and/or modify() are supported.
   3.351 + */
   3.352  static int inst2res(CMPIInstance *inst, void **res, CMPIStatus *status)
   3.353  {
   3.354 -   CMPIData data;
   3.355 -   char *inst_id;
   3.356 -   char uuid[MAX_SYSTEM_NAME_LEN];
   3.357 -   int ccode;
   3.358 -
   3.359 -   if (CMIsNullObject(inst) || res == NULL)
   3.360 -      return 0;
   3.361 -
   3.362 -   data = CMGetProperty(inst, "InstanceID", status);
   3.363 -   if ((status->rc != CMPI_RC_OK) || CMIsNullValue(data))
   3.364 -      return 0;
   3.365 +   (void)status;
   3.366 +   _RESOURCE *resource;
   3.367     
   3.368 -   inst_id = CMGetCharPtr(data.value.string);
   3.369 -   if ((inst_id == NULL) || (*inst_id == '\0'))
   3.370 +   /* Just return the CMPIInstance.  Convert in modify(). */
   3.371 +   resource = (_RESOURCE *)calloc(1, sizeof(_RESOURCE));
   3.372 +   if (resource == NULL)
   3.373        return 0;
   3.374  
   3.375 -   /* Extract the disk uuid from InstanceID property. */
   3.376 -   if (!_CMPIStrncpyDeviceNameFromID(uuid, inst_id, MAX_SYSTEM_NAME_LEN))
   3.377 -      return 0;
   3.378 -
   3.379 -   if (!xen_utils_validate_session(&session)) {
   3.380 -      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.381 -                   ("--- Unable to establish connection with Xend"));
   3.382 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   3.383 -                           "Unable to establish connection with Xend");
   3.384 -      return 0;
   3.385 -   }
   3.386 -
   3.387 -   if (!xen_vbd_get_record(session->xen,
   3.388 -                           (xen_vbd_record **)res, (xen_vbd)uuid)) {
   3.389 -      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   3.390 -                   ("--- xen_vbd_get_record failed:"));
   3.391 -      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   3.392 -                            xen_utils_trace_error(session->xen));
   3.393 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   3.394 -                           "xen_vbd_get_record failed");
   3.395 -      return 0;
   3.396 -   }
   3.397 -
   3.398 +   resource->u.cmpi_inst = inst;
   3.399 +   *res = (void *)resource;
   3.400     return 1;
   3.401  }
   3.402  
     4.1 --- a/src/Xen_Processor.c	Mon Jun 11 15:38:51 2007 -0600
     4.2 +++ b/src/Xen_Processor.c	Tue Jun 12 17:44:58 2007 -0600
     4.3 @@ -77,10 +77,8 @@ static int load()
     4.4  }
     4.5  
     4.6  
     4.7 -static int unload(CMPIBoolean terminating)
     4.8 +static int unload()
     4.9  {
    4.10 -   (void) terminating;
    4.11 -   
    4.12     if (session) {
    4.13        xen_utils_xen_close(session);
    4.14        session = NULL;
    4.15 @@ -90,6 +88,13 @@ static int unload(CMPIBoolean terminatin
    4.16  }
    4.17  
    4.18  
    4.19 +/*
    4.20 + * beginEnum is called before any function that uses the xen session.
    4.21 + * In the event this provider is loaded but has not been invoked for some
    4.22 + * time, the xen session object will be validated in beginEnum.  Functions
    4.23 + * called directly after beginEnum (e.g. get, getNext, modify) should
    4.24 + * set the session 'ok' flag.
    4.25 + */
    4.26  static int beginEnum(void **res_list, CMPIStatus *status)
    4.27  {
    4.28     _RESOURCES *resources;
    4.29 @@ -115,6 +120,8 @@ static int beginEnum(void **res_list, CM
    4.30     if(!xen_host_get_resident_vms(session->xen, &vms, session->host)) {
    4.31        _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
    4.32                     ("--- Failed to retrieve list of domains from host"));
    4.33 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
    4.34 +                            xen_utils_trace_error(session->xen));
    4.35        CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
    4.36                             "Failed to retrieve list of domains from host");
    4.37        free(resources);
    4.38 @@ -133,6 +140,8 @@ static int beginEnum(void **res_list, CM
    4.39        if (!xen_vm_get_record(session->xen, &vm_rec, vms->contents[vm_ndx])) {
    4.40           _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
    4.41                        ("--- Failed to retrieve VM record from xend"));
    4.42 +         _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
    4.43 +                               xen_utils_trace_error(session->xen));
    4.44           CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
    4.45                                "Failed to retrieve VM record from xend");
    4.46           goto Error;
    4.47 @@ -237,16 +246,104 @@ static int getNext(void *res_list, void 
    4.48  }
    4.49  
    4.50  
    4.51 -static int get(void *res_list, void **res, CMPIStatus *status)
    4.52 +static int get(void *res_list, const CMPIObjectPath *op, void **res, CMPIStatus *status)
    4.53  {
    4.54 -   if (res == NULL || *res == NULL)
    4.55 +   CMPIData data;
    4.56 +   char *prop_val;
    4.57 +   _RESOURCE *resource;
    4.58 +   
    4.59 +   (void)res_list;
    4.60 +
    4.61 +   if (CMIsNullObject(op) || res == NULL)
    4.62 +      return 0;
    4.63 +
    4.64 +   /* Obtain the target domain name from instance's "SystemName" property. */
    4.65 +   data = CMGetKey(op, "SystemName", status);
    4.66 +   if ((status->rc != CMPI_RC_OK) || CMIsNullValue(data))
    4.67 +      return 0;
    4.68 +
    4.69 +   prop_val = CMGetCharPtr(data.value.string);
    4.70 +   if ((prop_val == NULL) || (*prop_val == '\0'))
    4.71 +      return 0;
    4.72 +
    4.73 +   session->xen->ok = true;
    4.74 +
    4.75 +   /* Get the domain data for the target domain name. */
    4.76 +   xen_vm_set *vms;
    4.77 +   if (!xen_vm_get_by_name_label(session->xen, &vms, prop_val)) {
    4.78 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_WARNING,
    4.79 +                   ("--- Failed to retrieve domain %s", prop_val));
    4.80 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
    4.81 +                            xen_utils_trace_error(session->xen));
    4.82 +      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_NOT_FOUND,
    4.83 +                           "Unable to retrieve domain");
    4.84 +      return 0;
    4.85 +   }
    4.86 +
    4.87 +   assert(vms->size == 1);
    4.88 +   xen_vm_record *vm_rec;
    4.89 +   if (!xen_vm_get_record(session->xen, &vm_rec, vms->contents[0])) {
    4.90 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
    4.91 +                   ("--- Failed to retrieve domain record for %s", prop_val));
    4.92 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
    4.93 +                            xen_utils_trace_error(session->xen));
    4.94 +      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
    4.95 +                           "Unable to retrieve domain record from xend");
    4.96 +      xen_vm_set_free(vms);
    4.97        return 0;
    4.98 -   /*
    4.99 -    * WARNING!
   4.100 -    * What needs to be done here?  It looks as though inst2res() will have
   4.101 -    * been called on parameter res before a call to this function - in
   4.102 -    * which case res will be populated.
   4.103 +   }
   4.104 +
   4.105 +   xen_vm_set_free(vms);
   4.106 +
   4.107 +   /* 
   4.108 +    * Xen_Processor instances only exist when domain is not inactive.
   4.109 +    * Incoming object path must be from a previously active domain.
   4.110      */
   4.111 +   if (vm_rec->power_state == XEN_VM_POWER_STATE_HALTED) {
   4.112 +         CMSetStatus(status, CMPI_RC_ERR_NOT_FOUND);
   4.113 +         xen_vm_record_free(vm_rec);
   4.114 +         return 0;
   4.115 +   }
   4.116 +   xen_vm_record_free(vm_rec);
   4.117 +   
   4.118 +   /* Create resource. */
   4.119 +   resource = (_RESOURCE *)malloc(sizeof(_RESOURCE));
   4.120 +   if (resource == NULL) {
   4.121 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   4.122 +                   ("--- Failed to malloc memory for processor resource"));
   4.123 +      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   4.124 +                           "Failed to malloc memory for processor resource");
   4.125 +      return 0;
   4.126 +   }
   4.127 +
   4.128 +   /* Populate domain_name and vcpu_id fields. */
   4.129 +   resource->domain_name = strdup(prop_val);
   4.130 +
   4.131 +   /* Set the vcpu_id from the DeviceID */
   4.132 +   data = CMGetKey(op, "DeviceID", status);
   4.133 +   if ((status->rc != CMPI_RC_OK) || CMIsNullValue(data)) {
   4.134 +      free(resource->domain_name);
   4.135 +      free(resource);
   4.136 +      return 0;
   4.137 +   }
   4.138 +
   4.139 +   prop_val = CMGetCharPtr(data.value.string);
   4.140 +   if ((prop_val == NULL) || (*prop_val == '\0')) {
   4.141 +      free(resource->domain_name);
   4.142 +      free(resource);
   4.143 +      return 0;
   4.144 +   }
   4.145 +
   4.146 +   char *p;
   4.147 +   if ((p = strstr(prop_val, "VCPU")) == NULL) {
   4.148 +      free(resource->domain_name);
   4.149 +      free(resource);
   4.150 +      return 0;
   4.151 +   }
   4.152 +
   4.153 +   resource->vcpu_id = atoi(p + 4);
   4.154 +
   4.155 +   *res = (void *)resource;
   4.156     return 1;
   4.157  }
   4.158  
   4.159 @@ -275,7 +372,8 @@ static int delete(void **res_list, void 
   4.160  }
   4.161  
   4.162  
   4.163 -static int modify(void **res_list, void *res, CMPIStatus *status)
   4.164 +static int modify(void **res_list, void *target_res,
   4.165 +                  void *modified_res, CMPIStatus *status)
   4.166  {
   4.167     return -1; /* unsupported */
   4.168  }
   4.169 @@ -299,8 +397,8 @@ static int res2inst(void *res, CMPIInsta
   4.170     CMSetProperty(inst, "CreationClassName",
   4.171                   (CMPIValue *)"Xen_Processor", CMPI_chars);
   4.172     
   4.173 -   char deviceid[1024];
   4.174 -   sprintf(deviceid, "VCPU%d", resource->vcpu_id);
   4.175 +   char deviceid[128];
   4.176 +   snprintf(deviceid, 128, "VCPU%d", resource->vcpu_id);
   4.177     CMSetProperty(inst, "DeviceID",(CMPIValue *)deviceid, CMPI_chars);
   4.178  
   4.179     CMSetProperty(inst, "Caption",(CMPIValue *)"Processor", CMPI_chars);
   4.180 @@ -314,64 +412,13 @@ static int res2inst(void *res, CMPIInsta
   4.181  }
   4.182  
   4.183  
   4.184 -/* Set resource data from the CMPIInstance properties. */ 
   4.185 +/*
   4.186 + * Set resource data from the CMPIInstance properties.  Only needs to
   4.187 + * be implemented if add() and/or modify() are supported.
   4.188 + */
   4.189  static int inst2res(CMPIInstance *inst, void **res, CMPIStatus *status)
   4.190  {
   4.191 -   CMPIData data;
   4.192 -   char *prop_val;
   4.193 -   _RESOURCE *resource;
   4.194 -   
   4.195 -   if (CMIsNullObject(inst) || res == NULL)
   4.196 -      return 0;
   4.197 -
   4.198 -   /* Obtain the target domain name from instance's "SystemName" property. */
   4.199 -   data = CMGetProperty(inst, "SystemName", status);
   4.200 -   if ((status->rc != CMPI_RC_OK) || CMIsNullValue(data))
   4.201 -      return 0;
   4.202 -
   4.203 -   prop_val = CMGetCharPtr(data.value.string);
   4.204 -   if ((prop_val == NULL) || (*prop_val == '\0'))
   4.205 -      return 0;
   4.206 -
   4.207 -   /* Create resource. */
   4.208 -   resource = (_RESOURCE *)malloc(sizeof(_RESOURCE));
   4.209 -   if (resource == NULL) {
   4.210 -      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   4.211 -                   ("--- Failed to malloc memory for processor resource"));
   4.212 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   4.213 -                           "Failed to malloc memory for processor resource");
   4.214 -      return 0;
   4.215 -   }
   4.216 -
   4.217 -   /* Populate domain_name and vcpu_id fields. */
   4.218 -   resource->domain_name = strdup(prop_val);
   4.219 -
   4.220 -   /* Set the vcpu_id from the DeviceID */
   4.221 -   data = CMGetProperty(inst, "DeviceID", status);
   4.222 -   if ((status->rc != CMPI_RC_OK) || CMIsNullValue(data)) {
   4.223 -      free(resource->domain_name);
   4.224 -      free(resource);
   4.225 -      return 0;
   4.226 -   }
   4.227 -
   4.228 -   prop_val = CMGetCharPtr(data.value.string);
   4.229 -   if ((prop_val == NULL) || (*prop_val == '\0')) {
   4.230 -      free(resource->domain_name);
   4.231 -      free(resource);
   4.232 -      return 0;
   4.233 -   }
   4.234 -
   4.235 -   char *p;
   4.236 -   if ((p = strstr(prop_val, "VCPU")) == NULL) {
   4.237 -      free(resource->domain_name);
   4.238 -      free(resource);
   4.239 -      return 0;
   4.240 -   }
   4.241 -
   4.242 -   resource->vcpu_id = atoi(p + 4);
   4.243 -
   4.244 -   *res = (void *)resource;
   4.245 -   return 1;
   4.246 +   return -1;  /* unsupported */
   4.247  }
   4.248  
   4.249  
     5.1 --- a/src/Xen_ProcessorSettingData.c	Mon Jun 11 15:38:51 2007 -0600
     5.2 +++ b/src/Xen_ProcessorSettingData.c	Tue Jun 12 17:44:58 2007 -0600
     5.3 @@ -20,626 +20,438 @@
     5.4  // Description:
     5.5  // ============================================================================
     5.6  
     5.7 -/* Include the required CMPI data types, function headers, and macros */
     5.8 +/* Common declarations for each CMPI "Cimpler" instance provider */
     5.9 +// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    5.10  #include "cmpidt.h"
    5.11 -#include "cmpift.h"
    5.12  #include "cmpimacs.h"
    5.13 -
    5.14 -/* Include utility functions */
    5.15 -#include "cmpiutil.h"
    5.16 +#include "cmpilr.h"
    5.17  
    5.18 -/* Include _SBLIM_TRACE() logging support */
    5.19 -#include "cmpitrace.h"
    5.20  
    5.21 -/* Include Xen utilities */
    5.22 -#include "xen_utils.h"
    5.23 -
    5.24 -/* Include the abstract resource access functions and abstracted _RESOURCES and _RESOURCE data types. */
    5.25 -#include "Xen_ProcessorSettingData_Resource.h"
    5.26 +static const CMPIInstanceMI* mi;
    5.27  
    5.28  
    5.29 -// ----------------------------------------------------------------------------
    5.30 -// COMMON GLOBAL VARIABLES
    5.31 -// ----------------------------------------------------------------------------
    5.32 +#define _BROKER (((CMPIResource*)(mi->hdl))->brkr)
    5.33 +#define _CLASS (((CMPIResource*)(mi->hdl))->cn)
    5.34 +// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    5.35 +
    5.36 +#include <stdlib.h>
    5.37 +#include <string.h>
    5.38 +#include <assert.h>
    5.39 +
    5.40 +#include <xen_common.h>
    5.41 +#include <xen_vm.h>
    5.42 +#include <xen_vm_metrics.h>
    5.43 +#include <xen_string_string_map.h>
    5.44 +#include <xen_vm_power_state.h>
    5.45 +
    5.46 +#include "cmpitrace.h"
    5.47 +#include "xen_utils.h"
    5.48 +#include "provider_common.h"
    5.49  
    5.50 -/* Handle to the CIM broker. Initialized when the provider lib is loaded. */
    5.51 -static const CMPIBroker *_BROKER;
    5.52 +
    5.53 +/* C struct to store the data for a single resource. */
    5.54 +typedef struct {
    5.55 +   int is_vm_record;
    5.56 +   union
    5.57 +   {
    5.58 +      xen_vm_record *vm_rec;
    5.59 +      CMPIInstance *cmpi_inst;
    5.60 +   } u;
    5.61 +} _RESOURCE;
    5.62 +
    5.63 +
    5.64 +/* C struct to store the data for all resources. */
    5.65 +typedef struct {
    5.66 +   xen_vm_set *domains;
    5.67 +   size_t cur_domain;
    5.68 +} _RESOURCES;
    5.69 +
    5.70  
    5.71  /* Xen session object.  Initialize when the provider is loaded, close when
    5.72   * provider unloaded. */
    5.73  static xen_utils_session *session = NULL;
    5.74  
    5.75  
    5.76 -// ============================================================================
    5.77 -// CMPI INSTANCE PROVIDER FUNCTION TABLE
    5.78 -// ============================================================================
    5.79 -
    5.80 -// ----------------------------------------------------------------------------
    5.81 -// Info for the class supported by the instance provider
    5.82 -// ----------------------------------------------------------------------------
    5.83 -
    5.84 -/* Name of the class implemented by this instance provider. */
    5.85 -/*** CUSTOMIZE FOR EACH PROVIDER ***/
    5.86 -static char * _CLASSNAME = "Xen_ProcessorSettingData";
    5.87 -
    5.88 -/* NULL terminated list of key properties of this class. */
    5.89 -/*** CUSTOMIZE FOR EACH PROVIDER ***/
    5.90 -const static char * _KEYNAMES[] = {"InstanceID", NULL};
    5.91 +static int load()
    5.92 +{
    5.93 +   /* Initialized Xen session object. */
    5.94 +   if (!session)
    5.95 +      xen_utils_xen_init(&session);
    5.96  
    5.97 -// ----------------------------------------------------------------------------
    5.98 -// Cleanup()
    5.99 -// Perform any necessary cleanup immediately before this provider is unloaded.
   5.100 -// ----------------------------------------------------------------------------
   5.101 -static CMPIStatus Cleanup(
   5.102 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   5.103 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   5.104 -        CMPIBoolean terminating)   /* [in] True if MB is terminating */
   5.105 +   return 1;
   5.106 +}
   5.107 +
   5.108 +
   5.109 +static int unload()
   5.110  {
   5.111 -   CMPIStatus status = { CMPI_RC_OK, NULL };	/* Return status of CIM operations. */
   5.112 -
   5.113 -   _SBLIM_ENTER("Cleanup");
   5.114 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   5.115 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   5.116 -
   5.117     if (session) {
   5.118        xen_utils_xen_close(session);
   5.119        session = NULL;
   5.120     }
   5.121 -   _SBLIM_RETURNSTATUS(status);
   5.122 +
   5.123 +   return 1;
   5.124  }
   5.125  
   5.126 -// ----------------------------------------------------------------------------
   5.127 -// EnumInstanceNames()
   5.128 -// Return a list of all the instances names (return their object paths only).
   5.129 -// ----------------------------------------------------------------------------
   5.130 -static CMPIStatus EnumInstanceNames(
   5.131 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   5.132 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   5.133 -		const CMPIResult * results,		/* [out] Results of this operation. */
   5.134 -		const CMPIObjectPath * reference) 	/* [in] Contains target namespace and classname. */
   5.135 +
   5.136 +/*
   5.137 + * beginEnum is called before any function that uses the xen session.
   5.138 + * In the event this provider is loaded but has not been invoked for some
   5.139 + * time, the xen session object will be validated in beginEnum.  Functions
   5.140 + * called directly after beginEnum (e.g. get, getNext, modify) should
   5.141 + * set the session 'ok' flag.
   5.142 + */
   5.143 +static int beginEnum(void **res_list, CMPIStatus *status)
   5.144  {
   5.145 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   5.146 -   _RESOURCES * resources = NULL;			/* Handle to the list of system resources. */
   5.147 -   _RESOURCE * resource;			/* Handle to each system resource. */
   5.148 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   5.149 -   int found = 0;				/* Found any instances? */
   5.150 -  
   5.151 -   _SBLIM_ENTER("EnumInstanceNames");
   5.152 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   5.153 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   5.154 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   5.155 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   5.156 -
   5.157 +   _RESOURCES *resources;
   5.158 +   
   5.159     if (!xen_utils_validate_session(&session)) {
   5.160 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
   5.161 -      goto exit;
   5.162 -   }
   5.163 -
   5.164 -   /* Get a handle to the list of system resources. */
   5.165 -   if (!Xen_ProcessorSettingData_getResources(session, &resources)) {
   5.166 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   5.167 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   5.168 -      goto exit;
   5.169 -   }
   5.170 -
   5.171 -   /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
   5.172 -   while (Xen_ProcessorSettingData_getNextResource(session, resources, &resource)) {
   5.173 -      /* Create a new CMPIInstance to store this resource. */
   5.174 -      CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
   5.175 -      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
   5.176 -         _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
   5.177 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
   5.178 -         goto exit;
   5.179 -      }
   5.180 -
   5.181 -      /* Set the instance property values from the resource data. */
   5.182 -      if (!Xen_ProcessorSettingData_setInstanceFromResource(session, resource, instance, _BROKER)) {
   5.183 -         _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
   5.184 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
   5.185 -         goto exit;
   5.186 -      }
   5.187 -
   5.188 -      /* Free the resource data. */
   5.189 -      if (!Xen_ProcessorSettingData_freeResource(resource)) {
   5.190 -         _SBLIM_TRACE(1,("--- _freeResource() failed"));
   5.191 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   5.192 -         goto exit;
   5.193 -      }
   5.194 -
   5.195 -      /* Return the CMPIObjectPath for this instance. */
   5.196 -      CMPIObjectPath * objectpath = CMGetObjectPath(instance, &status);
   5.197 -      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
   5.198 -         _SBLIM_TRACE(1,("--- CMGetObjectPath() failed - %s", CMGetCharPtr(status.msg)));
   5.199 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot get CMPIObjectPath for instance");
   5.200 -         goto exit;
   5.201 -      }
   5.202 -      CMSetNameSpace(objectpath, namespace); /* Note - CMGetObjectPath() does not preserve the namespace! */
   5.203 -     
   5.204 -      _SBLIM_TRACE(3,("--- objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, objectpath, NULL))));
   5.205 -      CMReturnObjectPath(results, objectpath);
   5.206 -      found++;
   5.207 -   }
   5.208 -
   5.209 -   _SBLIM_TRACE(2,("--- %d object paths found", found));
   5.210 -   CMReturnDone(results);
   5.211 -
   5.212 -exit:
   5.213 -   /* Free the list of system resources. */
   5.214 -   if (!Xen_ProcessorSettingData_freeResources(resources)) {
   5.215 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   5.216 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   5.217 -   }
   5.218 -  
   5.219 -   _SBLIM_RETURNSTATUS(status);
   5.220 -}
   5.221 -
   5.222 -// ----------------------------------------------------------------------------
   5.223 -// EnumInstances()
   5.224 -// Return a list of all the instances (return all the instance data).
   5.225 -// ----------------------------------------------------------------------------
   5.226 -static CMPIStatus EnumInstances(
   5.227 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   5.228 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   5.229 -		const CMPIResult * results,		/* [out] Results of this operation. */
   5.230 -		const CMPIObjectPath * reference,	/* [in] Contains target namespace and classname. */
   5.231 -		const char ** properties)	/* [in] List of desired properties (NULL=all). */
   5.232 -{
   5.233 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   5.234 -   _RESOURCES * resources = NULL;			/* Handle to the list of system resources. */
   5.235 -   _RESOURCE * resource;			/* Handle to each system resource. */
   5.236 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   5.237 -   int found = 0;				/* Found any resource instances? */
   5.238 -
   5.239 -   _SBLIM_ENTER("EnumInstances");
   5.240 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   5.241 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   5.242 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   5.243 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   5.244 -
   5.245 -   if (!xen_utils_validate_session(&session)) {
   5.246 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
   5.247 -      goto exit;
   5.248 -   }
   5.249 -
   5.250 -   /* Get a handle to the list of system resources. */
   5.251 -   if (!Xen_ProcessorSettingData_getResources(session, &resources)) {
   5.252 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   5.253 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   5.254 -      goto exit;
   5.255 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   5.256 +                   ("--- Unable to establish connection with Xend"));
   5.257 +      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   5.258 +                           "Unable to establish connection with Xend");
   5.259 +      return 0;
   5.260     }
   5.261  
   5.262 -   /* Enumerate thru the list of system resources and return a CMPIInstance for each. */
   5.263 -   while (Xen_ProcessorSettingData_getNextResource(session, resources, &resource)) {
   5.264 -      /* Create a new CMPIInstance to store this resource. */
   5.265 -      CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
   5.266 -      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
   5.267 -         _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
   5.268 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
   5.269 -         goto exit;
   5.270 -      }
   5.271 -
   5.272 -      /* Setup a filter to only return the desired properties. */
   5.273 -      status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
   5.274 -      if (status.rc != CMPI_RC_OK) {
   5.275 -         _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
   5.276 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
   5.277 -         goto exit;
   5.278 -      }
   5.279 -
   5.280 -      /* Set the instance property values from the resource data. */
   5.281 -      if (!Xen_ProcessorSettingData_setInstanceFromResource(session, resource, instance, _BROKER)) {
   5.282 -         _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
   5.283 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
   5.284 -         goto exit;
   5.285 -      }
   5.286 -
   5.287 -      /* Free the resource data. */
   5.288 -      if (!Xen_ProcessorSettingData_freeResource(resource)) {
   5.289 -         _SBLIM_TRACE(1,("--- _freeResource() failed"));
   5.290 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   5.291 -         goto exit;
   5.292 -      }
   5.293 -
   5.294 -      /* Return the CMPIInstance for this instance. */
   5.295 -      _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
   5.296 -      CMReturnInstance(results, instance);
   5.297 -      found++;
   5.298 -   }
   5.299 -
   5.300 -   _SBLIM_TRACE(2,("--- %d instances found", found));
   5.301 -   CMReturnDone(results);
   5.302 -
   5.303 -exit:
   5.304 -   /* Free the list of system resources. */
   5.305 -   if (!Xen_ProcessorSettingData_freeResources(resources)) {
   5.306 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   5.307 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   5.308 -   }
   5.309 -
   5.310 -   _SBLIM_RETURNSTATUS(status);
   5.311 -}
   5.312 +   /* malloc a new handle for the resources list. */
   5.313 +   resources = (_RESOURCES *)calloc(1, sizeof(_RESOURCES));
   5.314 +   if (resources == NULL)
   5.315 +      return 0;
   5.316  
   5.317 -// ----------------------------------------------------------------------------
   5.318 -// GetInstance()
   5.319 -// Return the instance data for the specified instance only.
   5.320 -// ----------------------------------------------------------------------------
   5.321 -static CMPIStatus GetInstance(
   5.322 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   5.323 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   5.324 -		const CMPIResult * results,		/* [out] Results of this operation. */
   5.325 -		const CMPIObjectPath * reference,	/* [in] Contains the target namespace, classname and object path. */
   5.326 -		const char ** properties)		/* [in] List of desired properties (NULL=all). */
   5.327 -{
   5.328 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   5.329 -   _RESOURCES * resources = NULL;			/* Handle to the list of system resources. */
   5.330 -   _RESOURCE * resource;			/* Handle to the system resource. */
   5.331 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   5.332 -   int found = 0;				/* Found the target instance? */
   5.333 -
   5.334 -   _SBLIM_ENTER("GetInstance");
   5.335 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   5.336 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   5.337 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   5.338 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   5.339 -
   5.340 -   if (!xen_utils_validate_session(&session)) {
   5.341 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
   5.342 -      goto exit;
   5.343 -   }
   5.344 -
   5.345 -   /* Get a handle to the list of system resources. */
   5.346 -   if (!Xen_ProcessorSettingData_getResources(session, &resources)) {
   5.347 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   5.348 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   5.349 -      goto exit;
   5.350 -   }
   5.351 -
   5.352 -   /* Get the target resource. */
   5.353 -   found = Xen_ProcessorSettingData_getResourceForObjectPath(session, resources, &resource, reference);
   5.354 -   if (!found || (resource == NULL)) {
   5.355 -      _SBLIM_TRACE(1,("--- Target instance not found"));
   5.356 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
   5.357 -      goto exit;
   5.358 -   }
   5.359 -
   5.360 -   /* Create a new CMPIInstance to store this resource. */
   5.361 -   CMPIInstance * instance = _CMNewInstance(_BROKER, namespace, _CLASSNAME, &status);
   5.362 -   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instance)) {
   5.363 -      _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg)));
   5.364 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance");
   5.365 -      goto exit;
   5.366 -   }
   5.367 -
   5.368 -   /* Setup a filter to only return the desired properties. */
   5.369 -   status = CMSetPropertyFilter(instance, properties, _KEYNAMES);
   5.370 -   if (status.rc != CMPI_RC_OK) {
   5.371 -      _SBLIM_TRACE(1, ("--- CMSetPropertyFilter() failed - %s", CMGetCharPtr(status.msg)));
   5.372 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Cannot set property filter");
   5.373 -      goto exit;
   5.374 -   }
   5.375 -
   5.376 -   /* Set the instance property values from the resource data. */
   5.377 -   if (!Xen_ProcessorSettingData_setInstanceFromResource(session, resource, instance, _BROKER)) {
   5.378 -      _SBLIM_TRACE(1,("--- _setInstanceFromResource() failed"));
   5.379 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set property values from resource data");
   5.380 -      goto exit;
   5.381 -   }
   5.382 -
   5.383 -   /* Free the resource data. */
   5.384 -   if (!Xen_ProcessorSettingData_freeResource(resource)) {
   5.385 -      _SBLIM_TRACE(1,("--- _freeResource() failed"));
   5.386 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   5.387 -      goto exit;
   5.388 +   if(!xen_host_get_resident_vms(session->xen, &(resources->domains),
   5.389 +                                 session->host)) {
   5.390 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   5.391 +                   ("--- Failed to retrieve list of domains from host"));
   5.392 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   5.393 +                            xen_utils_trace_error(session->xen));
   5.394 +      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   5.395 +                           "Failed to retrieve list of domains from host");
   5.396 +      free(resources);
   5.397 +      return 0;
   5.398     }
   5.399  
   5.400 -   /* Return the CMPIInstance for this instance. */
   5.401 -   _SBLIM_TRACE(3,("--- instance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, instance, NULL))));
   5.402 -   CMReturnInstance(results, instance);
   5.403 +   *res_list = (void *)resources;
   5.404 +   return 1;
   5.405 +}
   5.406  
   5.407 -   _SBLIM_TRACE(2,("--- instance found"));
   5.408 -   CMReturnDone(results);
   5.409  
   5.410 -exit:
   5.411 -   /* Free the list of system resources. */
   5.412 -   if (!Xen_ProcessorSettingData_freeResources(resources)) {
   5.413 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   5.414 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   5.415 +static void endEnum(void *res_list)
   5.416 +{
   5.417 +   if (res_list) {
   5.418 +      xen_vm_set_free(((_RESOURCES *)res_list)->domains);
   5.419 +      free(res_list);
   5.420     }
   5.421 -
   5.422 -   _SBLIM_RETURNSTATUS(status);
   5.423  }
   5.424  
   5.425 -// ----------------------------------------------------------------------------
   5.426 -// SetInstance()
   5.427 -// Save modified instance data for the specified instance.
   5.428 -// ----------------------------------------------------------------------------
   5.429 -static CMPIStatus SetInstance(
   5.430 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   5.431 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   5.432 -		const CMPIResult * results,		/* [out] Results of this operation. */
   5.433 -		const CMPIObjectPath * reference,	/* [in] Contains the target namespace, classname and object path. */
   5.434 -		const CMPIInstance * newinstance,	/* [in] Contains the new instance data. */
   5.435 -        const char **properties)
   5.436 +
   5.437 +/* Iterator to get the next resource from the resources list. */
   5.438 +static int getNext(void *res_list, void **res, CMPIStatus *status)
   5.439  {
   5.440 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   5.441 -   _RESOURCES * resources = NULL;			/* Handle to the list of system resources. */
   5.442 -   _RESOURCE * resource;	       		/* Handle to the system resource. */
   5.443 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   5.444 -   int found = 0;				/* Found the target instance? */
   5.445 +   _RESOURCES *resources = (_RESOURCES *)res_list;
   5.446 +   _RESOURCE *resource;
   5.447  
   5.448 -   _SBLIM_ENTER("SetInstance");
   5.449 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   5.450 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   5.451 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   5.452 -   _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
   5.453 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   5.454 +   if (resources == NULL)
   5.455 +      return 0;
   5.456  
   5.457 -   if (!xen_utils_validate_session(&session)) {
   5.458 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
   5.459 -      goto exit;
   5.460 -   }
   5.461 +   if (resources->cur_domain >= resources->domains->size)
   5.462 +      return 0;
   5.463  
   5.464 -   /* Get a handle to the list of system resources. */
   5.465 -   if (!Xen_ProcessorSettingData_getResources(session, &resources)) {
   5.466 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   5.467 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   5.468 -      goto exit;
   5.469 -   }
   5.470 +   /* Get memory for resource. */
   5.471 +   resource = (_RESOURCE *)calloc(1, sizeof(_RESOURCE));
   5.472 +   if (resource == NULL)
   5.473 +      return 0;
   5.474  
   5.475 -   /* Get the target resource. */
   5.476 -   found = Xen_ProcessorSettingData_getResourceForObjectPath(session, resources, &resource, reference);
   5.477 -   if (!found || (resource == NULL)) {
   5.478 -      _SBLIM_TRACE(1,("--- Target instance not found"));
   5.479 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
   5.480 -      goto exit;
   5.481 -   }
   5.482 -
   5.483 -   _SBLIM_TRACE(2,("--- instance found", found));
   5.484 -
   5.485 -   /* Update the target resource data with the new instance property values. */
   5.486 -   int rc = Xen_ProcessorSettingData_setResourceFromInstance(resource, newinstance, _BROKER);
   5.487 -
   5.488 -   /* Free the resource data. */
   5.489 -   if (!Xen_ProcessorSettingData_freeResource(resource)) {
   5.490 -      _SBLIM_TRACE(1,("--- _freeResource() failed"));
   5.491 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   5.492 -      goto exit;
   5.493 -   }
   5.494 +   resource->is_vm_record = 1;
   5.495  
   5.496 -   if (rc != 1) {
   5.497 -      if (rc == -1) {
   5.498 -         _SBLIM_TRACE(1,("--- _setResourceFromInstance() unsupported"));
   5.499 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
   5.500 -      } else {
   5.501 -         _SBLIM_TRACE(1,("--- _setResourceFromInstance() failed"));
   5.502 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to set resource data from instance properties");
   5.503 -      }
   5.504 -      goto exit;
   5.505 +   session->xen->ok = true;
   5.506 +   if (!xen_vm_get_record(session->xen, &(resource->u.vm_rec),
   5.507 +                          resources->domains->contents[resources->cur_domain])) {
   5.508 +      free(resource);
   5.509 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   5.510 +                   ("--- Failed to retrieve VM record from xend"));
   5.511 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   5.512 +                            xen_utils_trace_error(session->xen));
   5.513 +      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   5.514 +                           "Failed to retrieve VM record from xend");
   5.515 +      return 0;
   5.516     }
   5.517 -
   5.518 -exit:
   5.519 -   /* Free the list of system resources. */
   5.520 -   if (!Xen_ProcessorSettingData_freeResources(resources)) {
   5.521 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   5.522 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   5.523 -   }
   5.524 -
   5.525 -   _SBLIM_RETURNSTATUS(status);
   5.526 +   
   5.527 +   resources->cur_domain++;
   5.528 +   *res = (void *)resource;
   5.529 +   return 1;
   5.530  }
   5.531  
   5.532 -// ----------------------------------------------------------------------------
   5.533 -// CreateInstance()
   5.534 -// Create a new instance from the specified instance data.
   5.535 -// ----------------------------------------------------------------------------
   5.536 -static CMPIStatus CreateInstance(
   5.537 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   5.538 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   5.539 -		const CMPIResult * results,		/* [out] Results of this operation. */
   5.540 -		const CMPIObjectPath * reference,	/* [in] Contains the target namespace, classname and object path. */
   5.541 -		const CMPIInstance * newinstance)	/* [in] Contains the new instance data. */
   5.542 +
   5.543 +static int get(void *res_list, const CMPIObjectPath *op,
   5.544 +               void **res, CMPIStatus *status)
   5.545  {
   5.546 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   5.547 -   _RESOURCES * resources = NULL;			/* Handle to the list of system resources. */
   5.548 -   _RESOURCE * resource;			/* Handle to the system resource. */
   5.549 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   5.550 -   int found = 0;				/* Found the target instance? */
   5.551 +   CMPIData data;
   5.552 +   char *prop_val;
   5.553 +   _RESOURCE *resource;
   5.554 +   char sys_name[MAX_SYSTEM_NAME_LEN];
   5.555 +   
   5.556 +   (void)res_list;
   5.557 +   
   5.558 +   if (CMIsNullObject(op) || res == NULL)
   5.559 +      return 0;
   5.560 +
   5.561 +   /* Obtain the target domain name from instance's "SystemName" property. */
   5.562 +   data = CMGetKey(op, "InstanceID", status);
   5.563 +   if ((status->rc != CMPI_RC_OK) || CMIsNullValue(data))
   5.564 +      return 0;
   5.565  
   5.566 -   _SBLIM_ENTER("CreateInstance");
   5.567 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   5.568 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   5.569 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   5.570 -   _SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER, newinstance, NULL))));
   5.571 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   5.572 +   prop_val = CMGetCharPtr(data.value.string);
   5.573 +   if ((prop_val == NULL) || (*prop_val == '\0'))
   5.574 +      return 0;
   5.575 +
   5.576 +   /* Extract the system name from InstanceID property. */
   5.577 +   if (!_CMPIStrncpySystemNameFromID(sys_name, prop_val, MAX_SYSTEM_NAME_LEN))
   5.578 +      return 0;
   5.579 +
   5.580 +   session->xen->ok = true;
   5.581  
   5.582 -   if (!xen_utils_validate_session(&session)) {
   5.583 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
   5.584 -      goto exit;
   5.585 +   /* Get the domain data for the target domain name. */
   5.586 +   xen_vm_set *vms;
   5.587 +   if (!xen_vm_get_by_name_label(session->xen, &vms, sys_name)) {
   5.588 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_WARNING,
   5.589 +                   ("--- Failed to retrieve domain %s", sys_name));
   5.590 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   5.591 +                            xen_utils_trace_error(session->xen));
   5.592 +      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_NOT_FOUND,
   5.593 +                           "Unable to retrieve domain");
   5.594 +      return 0;
   5.595     }
   5.596  
   5.597 -   /* WORKAROUND FOR PEGASUS BUG?! reference does not contain object path, only namespace & classname. */
   5.598 -   reference = CMGetObjectPath(newinstance, NULL);
   5.599 +   assert(vms->size == 1);
   5.600  
   5.601 -   /* Get a handle to the list of system resources. */
   5.602 -   if (!Xen_ProcessorSettingData_getResources(session, &resources)) {
   5.603 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   5.604 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   5.605 -      goto exit;
   5.606 +   /* Get memory for resource. */
   5.607 +   resource = (_RESOURCE *)calloc(1, sizeof(_RESOURCE));
   5.608 +   if (resource == NULL) {
   5.609 +      xen_vm_set_free(vms);
   5.610 +      return 0;
   5.611     }
   5.612 +   
   5.613 +   resource->is_vm_record = 1;
   5.614  
   5.615 -   /* Get the target resource. */
   5.616 -   found = Xen_ProcessorSettingData_getResourceForObjectPath(session, resources, &resource, reference);
   5.617 -
   5.618 -   /* Free the resource data. */
   5.619 -   if (!Xen_ProcessorSettingData_freeResource(resource)) {
   5.620 -      _SBLIM_TRACE(1,("--- _freeResource() failed"));
   5.621 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   5.622 -      goto exit;
   5.623 -   }
   5.624 -
   5.625 -   if (found) {
   5.626 -      _SBLIM_TRACE(1,("--- Target instance already exists"));
   5.627 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_ALREADY_EXISTS, "Target instance already exists");
   5.628 -      goto exit;
   5.629 +   if (!xen_vm_get_record(session->xen,
   5.630 +                          &(resource->u.vm_rec), vms->contents[0])) {
   5.631 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   5.632 +                   ("--- Failed to retrieve domain record for %s", prop_val));
   5.633 +      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   5.634 +                            xen_utils_trace_error(session->xen));
   5.635 +      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   5.636 +                           "Unable to retrieve domain record from xend");
   5.637 +      free(resource);
   5.638 +      xen_vm_set_free(vms);
   5.639 +      return 0;
   5.640     }
   5.641  
   5.642 -   /* Create a new resource with the new instance property values. */
   5.643 -   int rc = Xen_ProcessorSettingData_createResourceFromInstance(resources, &resource, newinstance, _BROKER);
   5.644 -   if (rc != 1) {
   5.645 -      if (rc == -1) {
   5.646 -         _SBLIM_TRACE(1,("--- _createResourceFromInstance() unsupported"));
   5.647 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
   5.648 -      } else {
   5.649 -         _SBLIM_TRACE(1,("--- _createResourceFromInstance() failed"));
   5.650 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to create resource data from instance properties");
   5.651 -      }
   5.652 -      goto exit;
   5.653 -   }
   5.654 -
   5.655 -   /* Return the object path for the newly created instance. */
   5.656 -   CMPIObjectPath * objectpath = CMGetObjectPath(newinstance, NULL);
   5.657 -   CMSetNameSpace(objectpath, namespace);
   5.658 -   CMReturnObjectPath(results, objectpath);
   5.659 -   CMReturnDone(results);
   5.660 -
   5.661 -exit:
   5.662 -   /* Free the list of system resources. */
   5.663 -   if (!Xen_ProcessorSettingData_freeResources(resources)) {
   5.664 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   5.665 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   5.666 -   }
   5.667 -
   5.668 -   _SBLIM_RETURNSTATUS(status);
   5.669 +   xen_vm_set_free(vms);
   5.670 +   *res = (void *)resource;
   5.671 +   return 1;
   5.672  }
   5.673  
   5.674 -// ----------------------------------------------------------------------------
   5.675 -// DeleteInstance()
   5.676 -// Delete or remove the specified instance from the system.
   5.677 -// ----------------------------------------------------------------------------
   5.678 -static CMPIStatus DeleteInstance(
   5.679 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   5.680 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   5.681 -		const CMPIResult * results,		/* [out] Results of this operation. */
   5.682 -		const CMPIObjectPath * reference)	/* [in] Contains the target namespace, classname and object path. */
   5.683 -{
   5.684 -   CMPIStatus status = {CMPI_RC_OK, NULL};	/* Return status of CIM operations. */
   5.685 -   _RESOURCES * resources = NULL;			/* Handle to the list of system resources. */
   5.686 -   _RESOURCE * resource;		/* Handle to the system resource. */
   5.687 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   5.688 -   int found = 0;				/* Found the target instance? */
   5.689 -
   5.690 -   _SBLIM_ENTER("DeleteInstance");
   5.691 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   5.692 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   5.693 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   5.694 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   5.695 -
   5.696 -   if (!xen_utils_validate_session(&session)) {
   5.697 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_METHOD_NOT_AVAILABLE, "Unable to connect to xen daemon");
   5.698 -      goto exit;
   5.699 -   }
   5.700 -
   5.701 -   /* Get a handle to the list of system resources. */
   5.702 -   if (!Xen_ProcessorSettingData_getResources(session, &resources)) {
   5.703 -      _SBLIM_TRACE(1,("--- _getResources() failed"));
   5.704 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to get list of system resources");
   5.705 -      goto exit;
   5.706 -   }
   5.707  
   5.708 -   /* Get the target resource. */
   5.709 -   found = Xen_ProcessorSettingData_getResourceForObjectPath(session, resources, &resource, reference);
   5.710 -   if (!found || (resource == NULL)) {
   5.711 -      _SBLIM_TRACE(1,("--- Target instance not found"));
   5.712 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "Target instance not found");
   5.713 -      goto exit;
   5.714 +static void release(void *res)
   5.715 +{
   5.716 +   if (res) {
   5.717 +      _RESOURCE *resource = (_RESOURCE *)res;
   5.718 +      if (resource->is_vm_record)
   5.719 +         xen_vm_record_free(resource->u.vm_rec);
   5.720 +      free(resource);
   5.721     }
   5.722 -
   5.723 -   _SBLIM_TRACE(2,("--- instance found", found));
   5.724 -
   5.725 -   /* Delete the target resource. */
   5.726 -   int rc = Xen_ProcessorSettingData_deleteResource(resources, resource);
   5.727 -
   5.728 -   /* Free the resource data. */
   5.729 -   if (!Xen_ProcessorSettingData_freeResource(resource)) {
   5.730 -      _SBLIM_TRACE(1,("--- _freeResource() failed"));
   5.731 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free resource data");
   5.732 -      goto exit;
   5.733 -   }
   5.734 +}
   5.735  
   5.736 -   if (rc != 1) {
   5.737 -      if (rc == -1) {
   5.738 -         _SBLIM_TRACE(1,("--- __deleteResource() unsupported"));
   5.739 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
   5.740 -      } else {
   5.741 -         _SBLIM_TRACE(1,("--- _deleteResource() failed"));
   5.742 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to delete resource");
   5.743 -      }
   5.744 -      goto exit;
   5.745 -   }
   5.746  
   5.747 -exit:
   5.748 -   /* Free the list of system resources. */
   5.749 -   if (!Xen_ProcessorSettingData_freeResources(resources)) {
   5.750 -      _SBLIM_TRACE(1,("--- _freeResources() failed"));
   5.751 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "Failed to free list of system resources");
   5.752 -   }
   5.753 -
   5.754 -   _SBLIM_RETURNSTATUS(status);
   5.755 +static int add(void **res_list, void *res, CMPIStatus *status)
   5.756 +{
   5.757 +   return -1; /* unsupported */
   5.758  }
   5.759  
   5.760  
   5.761 -// ----------------------------------------------------------------------------
   5.762 -// ExecQuery()
   5.763 -// Return a list of all the instances that satisfy the specified query filter.
   5.764 -// ----------------------------------------------------------------------------
   5.765 -static CMPIStatus ExecQuery(
   5.766 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   5.767 -		const CMPIContext * context,		/* [in] Additional context info, if any. */
   5.768 -		const CMPIResult * results,		/* [out] Results of this operation. */
   5.769 -		const CMPIObjectPath * reference,	/* [in] Contains the target namespace and classname. */
   5.770 -		const char * language,		/* [in] Name of the query language. */
   5.771 -		const char * query)			/* [in] Text of the query written in the query language. */
   5.772 +static int delete(void **res_list, void *res, CMPIStatus *status)
   5.773 +{
   5.774 +   return -1; /* unsupported */
   5.775 +}
   5.776 +
   5.777 +
   5.778 +static int modify(void **res_list, void *target_res,
   5.779 +                  void *modified_res, CMPIStatus *status)
   5.780  {
   5.781 -   CMPIStatus status = {CMPI_RC_OK, NULL};      /* Return status of CIM operations. */
   5.782 -   char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */
   5.783 +   CMPIInstance *cmpi_inst;
   5.784 +   xen_vm_record *vm_rec;
   5.785 +   CMPIData data;
   5.786 +   char buf[64];
   5.787 +
   5.788 +   if (target_res == NULL || modified_res == NULL)
   5.789 +      return 0;
   5.790 +   
   5.791 +   session->xen->ok = true;
   5.792 +
   5.793 +   cmpi_inst = ((_RESOURCE *)modified_res)->u.cmpi_inst;
   5.794 +   vm_rec = ((_RESOURCE *)target_res)->u.vm_rec;
   5.795  
   5.796 -   _SBLIM_ENTER("ExecQuery");
   5.797 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   5.798 -   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   5.799 -   _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL))));
   5.800 -   _SBLIM_TRACE(2, ("--- language=\"%s\"", language));
   5.801 -   _SBLIM_TRACE(2, ("--- query=\"%s\"", query));
   5.802 -   _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
   5.803 +   /* Allow modifying VirtualQuantity, Limit, Weight */
   5.804 +   data = CMGetProperty(cmpi_inst, "VirtualQuantity", status);
   5.805 +   if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(data)) {
   5.806 +      if (vm_rec->vcpus_at_startup != data.value.uint64) {
   5.807 +         xen_vm_set_vcpus_at_startup(session->xen,
   5.808 +                                     vm_rec->handle, data.value.uint64);
   5.809 +         xen_vm_set_vcpus_max(session->xen, vm_rec->handle, data.value.uint64);
   5.810 +         if (!session->xen->ok) {
   5.811 +            _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   5.812 +                         ("--- Failed to modify domain's vcpu configuration"));
   5.813 +            _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   5.814 +                                  xen_utils_trace_error(session->xen));
   5.815 +            CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   5.816 +                                 "Failed to modify domain's vcpu configuration");
   5.817 +            return 0;
   5.818 +         }
   5.819 +      }
   5.820 +   }
   5.821  
   5.822 -   /* EXECQUERY() IS NOT YET SUPPORTED FOR THIS CLASS */
   5.823 -   CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
   5.824 +   data = CMGetProperty(cmpi_inst, "Limit", status);
   5.825 +   if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(data)) {
   5.826 +      snprintf(buf, 64, "%lld", data.value.uint64);
   5.827 +      xen_utils_add_to_string_string_map("cap", buf, &(vm_rec->vcpus_params));
   5.828 +      if (!xen_vm_set_vcpus_params(session->xen,
   5.829 +                                   vm_rec->handle, vm_rec->vcpus_params)) {
   5.830 +         _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   5.831 +                      ("--- Failed to modify domain's vcpu configuration"));
   5.832 +         _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   5.833 +                               xen_utils_trace_error(session->xen));
   5.834 +         CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   5.835 +                              "Failed to modify domain's vcpu configuration");
   5.836 +         return 0;
   5.837 +      }
   5.838 +   }
   5.839  
   5.840 -   CMReturnDone(results);
   5.841 +   data = CMGetProperty(cmpi_inst, "Weight", status);
   5.842 +   if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(data)) {
   5.843 +      snprintf(buf, 64, "%d", data.value.uint32);
   5.844 +      xen_utils_add_to_string_string_map("weight", buf, &(vm_rec->vcpus_params));
   5.845 +      if (!xen_vm_set_vcpus_params(session->xen,
   5.846 +                                   vm_rec->handle, vm_rec->vcpus_params)) {
   5.847 +         _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   5.848 +                      ("--- Failed to modify domain's vcpu configuration"));
   5.849 +         _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   5.850 +                               xen_utils_trace_error(session->xen));
   5.851 +         CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   5.852 +                              "Failed to modify domain's vcpu configuration");
   5.853 +         return 0;
   5.854 +      }
   5.855 +   }
   5.856 +   
   5.857 +   /*
   5.858 +    * TODO:
   5.859 +    * vcpu -> pcpu affinity
   5.860 +    */
   5.861  
   5.862 -exit:
   5.863 -   _SBLIM_RETURNSTATUS(status);
   5.864 +   return 1;
   5.865  }
   5.866  
   5.867 -// ----------------------------------------------------------------------------
   5.868 -// Initialize()
   5.869 -// Perform any necessary initialization immediately after this provider is
   5.870 -// first loaded.
   5.871 -// ----------------------------------------------------------------------------
   5.872 -static void Initialize(
   5.873 -		CMPIInstanceMI * self,		/* [in] Handle to this provider (i.e. 'self'). */
   5.874 -		const CMPIContext * context)		/* [in] Additional context info, if any. */
   5.875 +
   5.876 +/* Set CMPIInstance properties from the resource data. */
   5.877 +static int res2inst(void *res, CMPIInstance *inst, CMPIStatus *status)
   5.878  {
   5.879 -   _SBLIM_ENTER("Initialize");
   5.880 -   _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
   5.881 -   //   _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL))));
   5.882 +   int int_prop_val;
   5.883 +   int64_t int64_prop_val;
   5.884 +   char buf[MAX_INSTANCEID_LEN];
   5.885 +   
   5.886 +   if (res == NULL)
   5.887 +      return 0;
   5.888 +
   5.889 +   if (CMIsNullObject(inst))
   5.890 +      return 0;
   5.891 +
   5.892 +   if (!((_RESOURCE *)res)->is_vm_record)
   5.893 +      return 0;
   5.894 +   
   5.895 +   xen_vm_record *vm_rec = ((_RESOURCE *)res)->u.vm_rec;
   5.896 +
   5.897 +   /* Set the CMPIInstance properties from the resource data. */
   5.898 +   snprintf(buf, MAX_INSTANCEID_LEN, "Xen:%s:Processor", vm_rec->name_label);
   5.899 +   CMSetProperty(inst, "InstanceID", (CMPIValue *)buf, CMPI_chars);
   5.900 +   CMSetProperty(inst, "ElementName", (CMPIValue *)"Processor", CMPI_chars);
   5.901 +   CMSetProperty(inst, "AllocationUnits",(CMPIValue *)"Cores", CMPI_chars);
   5.902 +
   5.903 +   int_prop_val = 3;
   5.904 +   /* 3 == CPU */
   5.905 +   CMSetProperty(inst, "ResourceType", (CMPIValue *)&int_prop_val, CMPI_uint16);
   5.906 +   /* 3 == Virtualized */
   5.907 +   CMSetProperty(inst, "ConsumerVisibility",
   5.908 +                 (CMPIValue *)&int_prop_val, CMPI_uint16);
   5.909 +
   5.910 +   int_prop_val = 1; /* true */
   5.911 +   CMSetProperty(inst, "AutomaticAllocation",
   5.912 +                 (CMPIValue *)&int_prop_val, CMPI_boolean);
   5.913 +   CMSetProperty(inst, "AutomaticDeallocation",
   5.914 +                 (CMPIValue *)&int_prop_val, CMPI_boolean);
   5.915  
   5.916 -   /* Initialized Xen session object. */
   5.917 -   if (session == NULL)
   5.918 -      xen_utils_xen_init(&session);
   5.919 +   int64_prop_val = vm_rec->vcpus_at_startup;
   5.920 +   /*
   5.921 +    * The CIM schema description of Reservation is:
   5.922 +    *    "This property specifies the amount of resource guaranteed
   5.923 +    *     to be available for this allocation."
   5.924 +    * For Xen, we'll guarantee the number of vcpus requested.
   5.925 +    */
   5.926 +   CMSetProperty(inst, "Reservation",
   5.927 +                 (CMPIValue *)&int64_prop_val, CMPI_uint64);
   5.928 +   CMSetProperty(inst, "VirtualQuantity",
   5.929 +                 (CMPIValue *)&int64_prop_val, CMPI_uint64);
   5.930  
   5.931 -   _SBLIM_RETURN();
   5.932 +   if (vm_rec->vcpus_params == NULL)
   5.933 +      return 1;
   5.934 +   
   5.935 +   /*
   5.936 +    * Weight, Limit, and HostResources properties map to
   5.937 +    * VM.vcpus_params as follows:
   5.938 +    *
   5.939 +    * Weight -> VM.vcpus_params[weight]
   5.940 +    * Limit  -> VM.vcpus_params[cap]
   5.941 +    * HostResources -> VM.vcpus_params[cpumap<n>] (n = vcpu num)
   5.942 +    */
   5.943 +
   5.944 +   char *map_val = xen_utils_get_from_string_string_map(vm_rec->vcpus_params, "weight");
   5.945 +   if (map_val) {
   5.946 +      int64_prop_val = atoll(map_val);
   5.947 +      CMSetProperty(inst, "Weight",(CMPIValue *)&int64_prop_val, CMPI_uint64);
   5.948 +   }
   5.949 +   map_val = xen_utils_get_from_string_string_map(vm_rec->vcpus_params, "cap");
   5.950 +   if (map_val) {
   5.951 +      int64_prop_val = atoll(map_val);
   5.952 +      CMSetProperty(inst, "Limit",(CMPIValue *)&int64_prop_val, CMPI_uint64);
   5.953 +   }
   5.954 +
   5.955 +   /*
   5.956 +    * TODO:
   5.957 +    * 1. vcpu -> pcpu affinity
   5.958 +    * 2. PoolID
   5.959 +    */
   5.960 +
   5.961 +   return 1;
   5.962  }
   5.963  
   5.964 -// ============================================================================
   5.965 -// CMPI INSTANCE PROVIDER FUNCTION TABLE SETUP
   5.966 -// ============================================================================
   5.967 -CMInstanceMIStub( , Xen_ProcessorSettingData, _BROKER, Initialize(&mi, ctx));
   5.968 +
   5.969 +/*
   5.970 + * Set resource data from the CMPIInstance properties.  Only needs to
   5.971 + * be implemented if add() and/or modify() are supported.
   5.972 + */
   5.973 +static int inst2res(CMPIInstance *inst, void **res, CMPIStatus *status)
   5.974 +{
   5.975 +   (void)status;
   5.976 +   _RESOURCE *resource;
   5.977 +   
   5.978 +   /* Just return the CMPIInstance.  Convert in modify(). */
   5.979 +   resource = (_RESOURCE *)calloc(1, sizeof(_RESOURCE));
   5.980 +   if (resource == NULL)
   5.981 +      return 0;
   5.982 +
   5.983 +   resource->u.cmpi_inst = inst;
   5.984 +   *res = (void *)resource;
   5.985 +   return 1;
   5.986 +}
   5.987 +
   5.988 +
   5.989 +/* Setup the CMPILR function tables and CMPILR instance provider entry point.*/
   5.990 +/* CMPILRInstanceMIStub(<CLASS_NAME>,<PROVIDER_NAME>,<CMPIInstanceMI_HANDLE>) */
   5.991 +CMPILRInstanceMIStub(Xen_ProcessorSettingData, Xen_ProcessorSettingData, mi)
     6.1 --- a/src/Xen_VirtualSystemManagementCapabilities.c	Mon Jun 11 15:38:51 2007 -0600
     6.2 +++ b/src/Xen_VirtualSystemManagementCapabilities.c	Tue Jun 12 17:44:58 2007 -0600
     6.3 @@ -65,10 +65,8 @@ static int load()
     6.4  }
     6.5  
     6.6  
     6.7 -static int unload(CMPIBoolean terminating)
     6.8 +static int unload()
     6.9  {
    6.10 -   (void) terminating;
    6.11 -   
    6.12     if (session) {
    6.13        xen_utils_xen_close(session);
    6.14        session = NULL;
    6.15 @@ -96,7 +94,6 @@ static void endEnum(void *res_list)
    6.16  
    6.17  static int getNext(void *res_list, void **res, CMPIStatus *status)
    6.18  {
    6.19 -   xen_host host = NULL;
    6.20     xen_host_record *host_rec;
    6.21  
    6.22     if (res_list == NULL || ((_RESOURCES *)res_list)->finished)
    6.23 @@ -112,17 +109,13 @@ static int getNext(void *res_list, void 
    6.24        return 0;
    6.25     }
    6.26  
    6.27 -   xen_session_get_this_host(session->xen, &host, session->xen);
    6.28 -   xen_host_get_record(session->xen, &host_rec, host);
    6.29 -   if (!session->xen->ok) {
    6.30 -      /* Error description in session object. */
    6.31 +   if (!xen_host_get_record(session->xen, &host_rec, session->host)) {
    6.32        _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
    6.33                     ("--- failed to retrieve host record from Xend:"));
    6.34        _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
    6.35                              xen_utils_trace_error(session->xen));
    6.36        CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
    6.37                             "Failed to retrieve host record from Xend");
    6.38 -      xen_host_free(host);
    6.39        return 0;
    6.40     }
    6.41        
    6.42 @@ -131,22 +124,21 @@ static int getNext(void *res_list, void 
    6.43  }
    6.44  
    6.45  
    6.46 -static int get(void *res_list, void **res, CMPIStatus *status)
    6.47 +static int get(void *res_list, const CMPIObjectPath *op,
    6.48 +               void **res, CMPIStatus *status)
    6.49  {
    6.50 -   xen_host host = NULL;
    6.51 +   (void)res_list;
    6.52 +   
    6.53     xen_host_record *host_rec;
    6.54  
    6.55 -   (void) res_list;
    6.56 -   
    6.57     if (!xen_utils_validate_session(&session)) {
    6.58 -      _SBLIM_TRACE(1, ("--- Unable to establish connection with Xend"));
    6.59 +      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, ("--- Unable to establish connection with Xend"));
    6.60        CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
    6.61                             "Unable to establish connection with Xend");
    6.62        return 0;
    6.63     }
    6.64  
    6.65 -   xen_session_get_this_host(session->xen, &host, session->xen);
    6.66 -   xen_host_get_record(session->xen, &host_rec, host);
    6.67 +   xen_host_get_record(session->xen, &host_rec, session->host);
    6.68     if (!session->xen->ok) {
    6.69        /* Error description in session object. */
    6.70        _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
    6.71 @@ -155,7 +147,6 @@ static int get(void *res_list, void **re
    6.72                              xen_utils_trace_error(session->xen));
    6.73        CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
    6.74                             "Failed to retrieve host record from Xend");
    6.75 -      xen_host_free(host);
    6.76        return 0;
    6.77     }
    6.78  
    6.79 @@ -182,7 +173,8 @@ static int delete(void **res_list, void 
    6.80  }
    6.81  
    6.82  
    6.83 -static int modify(void **res_list, void *res, CMPIStatus *status)
    6.84 +static int modify(void **res_list, void *target_res,
    6.85 +                  void *modified_res, CMPIStatus *status)
    6.86  {
    6.87     return -1; /* unsupported */
    6.88  }
    6.89 @@ -278,42 +270,13 @@ static int res2inst(void *res, CMPIInsta
    6.90  }
    6.91  
    6.92  
    6.93 -/* Set resource data from the CMPIInstance properties. */ 
    6.94 +/*
    6.95 + * Set resource data from the CMPIInstance properties.  Only needs to
    6.96 + * be implemented if add() and/or modify() are supported.
    6.97 + */
    6.98  static int inst2res(CMPIInstance *inst, void **res, CMPIStatus *status)
    6.99  {
   6.100 -   xen_host host = NULL;
   6.101 -   xen_host_record *host_rec;
   6.102 -
   6.103 -   (void) inst;
   6.104 -   
   6.105 -   /* 
   6.106 -    * Since we only have one VirtualSystemManagementService on this host
   6.107 -    * we'll just create the resource as usual.
   6.108 -    */
   6.109 -   if (!xen_utils_validate_session(&session)) {
   6.110 -      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   6.111 -                   ("--- Unable to establish connection with Xend"));
   6.112 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   6.113 -                           "Unable to establish connection with Xend");
   6.114 -      return 0;
   6.115 -   }
   6.116 -
   6.117 -   xen_session_get_this_host(session->xen, &host, session->xen);
   6.118 -   xen_host_get_record(session->xen, &host_rec, host);
   6.119 -   if (!session->xen->ok) {
   6.120 -      /* Error description in session object. */
   6.121 -      _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
   6.122 -                   ("--- failed to retrieve host record from Xend:"));
   6.123 -      _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
   6.124 -                            xen_utils_trace_error(session->xen));
   6.125 -      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED,
   6.126 -                           "Failed to retrieve host record from Xend");
   6.127 -      xen_host_free(host);
   6.128 -      return 0;
   6.129 -   }
   6.130 -
   6.131 -   *res = (void *)host_rec;
   6.132 -   return 1;
   6.133 +   return -1; /* unsupported */
   6.134  }
   6.135  
   6.136  
     7.1 --- a/src/cmpilr.c	Mon Jun 11 15:38:51 2007 -0600
     7.2 +++ b/src/cmpilr.c	Tue Jun 12 17:44:58 2007 -0600
     7.3 @@ -36,64 +36,6 @@
     7.4  
     7.5  
     7.6  /* ------------------------------------------------------------------------- */
     7.7 -
     7.8 -static int op2res(CMPIObjectPath* op, void** res, CMPIInstanceMI* mi)
     7.9 -{
    7.10 -   CMPIStatus status = {CMPI_RC_OK, NULL};
    7.11 -
    7.12 -   /* Create a new CMPIInstance for the CMPIObjectPath. */
    7.13 -   CMPIInstance* inst = CMNewInstance(_BROKER, op, &status);
    7.14 -   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(inst)) return 0;
    7.15 -
    7.16 -   /* Set the CMPIInstance key properties from the CMPIObjectPath keys. */
    7.17 -   int numkeys = CMGetKeyCount(op, &status);
    7.18 -   if (status.rc != CMPI_RC_OK) return 0;
    7.19 -   CMPIString* keyname;
    7.20 -   int i;
    7.21 -   for (i=0; i<numkeys; i++) {
    7.22 -      CMPIData key = CMGetKeyAt(op, i, &keyname, &status);
    7.23 -      if (status.rc != CMPI_RC_OK) return 0;
    7.24 -      status = CMSetProperty(inst, CMGetCharPtr(keyname), &(key.value), key.type);
    7.25 -      if (status.rc != CMPI_RC_OK) return 0;
    7.26 -   }
    7.27 -
    7.28 -   /* Create a partial resource from the CMPIInstance key properties. */
    7.29 -   return _FT->inst2res(inst, res, &status);
    7.30 -}
    7.31 -
    7.32 -/* ------------------------------------------------------------------------- */
    7.33 -
    7.34 -static int getres4op(void** res, CMPIObjectPath* op, CMPIInstanceMI* mi)
    7.35 -{
    7.36 -   CMPIStatus status = {CMPI_RC_OK, NULL};
    7.37 -
    7.38 -   int rc = op2res(op, res, mi);
    7.39 -   if (!rc || !*res) return 0;
    7.40 -
    7.41 -   void *resList = NULL;
    7.42 -   /* Get handle to the list of resources. */
    7.43 -   if (!_FT->beginEnum(&resList, &status))
    7.44 -       return 0;
    7.45 -
    7.46 -
    7.47 -   /* First try to get the target resource directly. */
    7.48 -   rc = _FT->get(resList, res, &status);
    7.49 -   if (rc == 0) { /* get() failed */
    7.50 -      _FT->release(*res);
    7.51 -      _FT->endEnum(resList);
    7.52 -      return 0;
    7.53 -   } else if (rc == -1) { /*get() unsupported */
    7.54 -      /*FIXME - enumerate all to look for match instead*/
    7.55 -      _FT->release(*res);
    7.56 -      _FT->endEnum(resList);
    7.57 -      return 0;
    7.58 -   }
    7.59 -
    7.60 -   _FT->endEnum(resList);
    7.61 -   return 1;
    7.62 -}
    7.63 -
    7.64 -/* ------------------------------------------------------------------------- */
    7.65  /* The generic CMPILR resource-agnostic CMPI instance provider functions.    */
    7.66  /* ------------------------------------------------------------------------- */
    7.67  
    7.68 @@ -104,7 +46,7 @@ CMPIStatus CMPILR_cleanup
    7.69     CMPIStatus status = {CMPI_RC_OK, NULL}; 
    7.70  
    7.71     /* Run the provider's unload() routine. */
    7.72 -   if (!_FT->unload(terminating)) {
    7.73 +   if (!_FT->unload()) {
    7.74        if (!terminating) CMSetStatusWithChars(_BROKER, &status, CMPI_RC_DO_NOT_UNLOAD, "unload() failed")
    7.75        else CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "unload() failed");
    7.76     }
    7.77 @@ -296,11 +238,21 @@ CMPIStatus CMPILR_getInstance
    7.78        }
    7.79     }
    7.80  
    7.81 +   /* Get handle to the list of resources. */
    7.82 +   void* resList = NULL;
    7.83 +   if (!_FT->beginEnum(&resList, &status)) {
    7.84 +      /* Set status to FAILED if beginEnum didn't update */
    7.85 +      if (status.rc == CMPI_RC_OK)
    7.86 +         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "beginEnum() failed");
    7.87 +      _SBLIM_RETURNSTATUS(status);
    7.88 +   }
    7.89 +
    7.90     /* Try to get the target resource. */ 
    7.91     void* res;
    7.92 -   int rc = getres4op(&res, (CMPIObjectPath*)ref, mi);
    7.93 +   int rc = _FT->get(resList, ref, &res, &status);
    7.94 +   _FT->endEnum(resList);
    7.95     if (!rc) {
    7.96 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "getres4op() failed");
    7.97 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "get() failed");
    7.98        _SBLIM_RETURNSTATUS(status);
    7.99     } 
   7.100  
   7.101 @@ -332,11 +284,21 @@ CMPIStatus CMPILR_createInstance
   7.102     _SBLIM_ENTER("CMPILR_createInstance");
   7.103     CMPIStatus status = {CMPI_RC_OK, NULL};
   7.104  
   7.105 +   /* Get handle to the list of resources. */
   7.106 +   void* resList = NULL;
   7.107 +   if (!_FT->beginEnum(&resList, &status)) {
   7.108 +      /* Set status to FAILED if beginEnum didn't update */
   7.109 +      if (status.rc == CMPI_RC_OK)
   7.110 +         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "beginEnum() failed");
   7.111 +      _SBLIM_RETURNSTATUS(status);
   7.112 +   }
   7.113 +
   7.114     /* Try to get the target resource. */
   7.115     void* res = NULL;
   7.116 -   int rc = getres4op(&res, (CMPIObjectPath*)ref, mi);
   7.117 +   int rc = _FT->get(resList, ref, &res, &status);
   7.118 +   _FT->release(res);
   7.119     if (rc) {
   7.120 -      _FT->release(res);
   7.121 +      _FT->endEnum(resList);
   7.122        CMSetStatus(&status, CMPI_RC_ERR_ALREADY_EXISTS);
   7.123        _SBLIM_RETURNSTATUS(status);
   7.124     }
   7.125 @@ -349,16 +311,6 @@ CMPIStatus CMPILR_createInstance
   7.126        _SBLIM_RETURNSTATUS(status);
   7.127     }
   7.128  
   7.129 -   /* Get handle to the list of resources. */
   7.130 -   void* resList = NULL;
   7.131 -   if (!_FT->beginEnum(&resList, &status)) {
   7.132 -      _FT->release(res);
   7.133 -      /* Set status to FAILED if beginEnum didn't update */
   7.134 -      if (status.rc == CMPI_RC_OK)
   7.135 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "beginEnum() failed");
   7.136 -      _SBLIM_RETURNSTATUS(status);
   7.137 -   }
   7.138 -
   7.139     /* Add the target resource. */
   7.140     rc = _FT->add(&resList, res, &status);
   7.141     if (rc != 1) {
   7.142 @@ -388,34 +340,38 @@ CMPIStatus CMPILR_modifyInstance
   7.143     _SBLIM_ENTER("CMPILR_modifyInstance");
   7.144     CMPIStatus status = {CMPI_RC_OK, NULL};
   7.145  
   7.146 -   /* Try to get the target resource. */
   7.147 -   void* res;
   7.148 -   int rc = getres4op(&res, (CMPIObjectPath*)ref, mi);
   7.149 -   if (!rc) {
   7.150 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "getres4op() failed");
   7.151 +   /* Get handle to the list of resources. */
   7.152 +   void* resList = NULL;
   7.153 +   if (!_FT->beginEnum(&resList, &status)) {
   7.154 +      /* Set status to FAILED if beginEnum didn't update */
   7.155 +      if (status.rc == CMPI_RC_OK)
   7.156 +         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "beginEnum() failed");
   7.157        _SBLIM_RETURNSTATUS(status);
   7.158     }
   7.159  
   7.160 -   rc = _FT->inst2res((CMPIInstance*)inst, &res, &status);
   7.161 -   if (!rc || !res) {
   7.162 +   /* Try to get the target resource. */
   7.163 +   void* targetRes;
   7.164 +   int rc = _FT->get(resList, ref, &targetRes, &status);
   7.165 +   if (!rc) {
   7.166 +      _FT->endEnum(resList);
   7.167 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "get() failed");
   7.168 +      _SBLIM_RETURNSTATUS(status);
   7.169 +   }
   7.170 +
   7.171 +   void *modifiedRes;
   7.172 +   rc = _FT->inst2res((CMPIInstance*)inst, &modifiedRes, &status);
   7.173 +   if (!rc || !modifiedRes) {
   7.174 +      _FT->release(targetRes);
   7.175 +      _FT->endEnum(resList);
   7.176        /* Honor status set by resource. */
   7.177        if (status.rc == CMPI_RC_OK)
   7.178           CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "inst2res() failed");
   7.179        _SBLIM_RETURNSTATUS(status);
   7.180     }
   7.181  
   7.182 -   /* Get handle to the list of resources. */
   7.183 -   void* resList = NULL;
   7.184 -   if (!_FT->beginEnum(&resList, &status)) {
   7.185 -      _FT->release(res);
   7.186 -      /* Set status to FAILED if beginEnum didn't update */
   7.187 -      if (status.rc == CMPI_RC_OK)
   7.188 -         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "beginEnum() failed");
   7.189 -      _SBLIM_RETURNSTATUS(status);
   7.190 -   }
   7.191  
   7.192 -   /* Add the target resource. */
   7.193 -   rc = _FT->modify(&resList, res, &status);
   7.194 +   /* Modify the resource. */
   7.195 +   rc = _FT->modify(&resList, targetRes, modifiedRes, &status);
   7.196     if (rc != 1) {
   7.197        /* Honor status set by resource. */
   7.198        if (status.rc == CMPI_RC_OK) {
   7.199 @@ -429,7 +385,8 @@ CMPIStatus CMPILR_modifyInstance
   7.200        }
   7.201     }
   7.202     
   7.203 -   _FT->release(res);
   7.204 +   _FT->release(targetRes);
   7.205 +   _FT->release(modifiedRes);
   7.206     _FT->endEnum(resList);
   7.207  
   7.208      _SBLIM_RETURNSTATUS(status);
   7.209 @@ -444,14 +401,6 @@ CMPIStatus CMPILR_deleteInstance
   7.210     _SBLIM_ENTER("CMPILR_deleteInstance");
   7.211     CMPIStatus status = {CMPI_RC_OK, NULL};
   7.212  
   7.213 -   /* Try to get the target resource. */
   7.214 -   void* res;
   7.215 -   int rc = getres4op(&res, (CMPIObjectPath*)ref, mi);
   7.216 -   if (!rc) {
   7.217 -      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "getres4op() failed");
   7.218 -      _SBLIM_RETURNSTATUS(status);
   7.219 -   }
   7.220 -
   7.221     /* Get handle to the list of resources. */
   7.222     void* resList = NULL;
   7.223     if (!_FT->beginEnum(&resList, &status)) {
   7.224 @@ -461,6 +410,15 @@ CMPIStatus CMPILR_deleteInstance
   7.225        _SBLIM_RETURNSTATUS(status);
   7.226     }
   7.227  
   7.228 +   /* Try to get the target resource. */
   7.229 +   void* res;
   7.230 +   int rc = _FT->get(resList, ref, &res, &status);
   7.231 +   if (!rc) {
   7.232 +      _FT->endEnum(resList);
   7.233 +      CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_FOUND, "get() failed");
   7.234 +      _SBLIM_RETURNSTATUS(status);
   7.235 +   }
   7.236 +
   7.237     /* Delete the target resource. */
   7.238     rc = _FT->delete(&resList, res, &status);
   7.239     if (rc != 1) {
     8.1 --- a/src/cmpilr.h	Mon Jun 11 15:38:51 2007 -0600
     8.2 +++ b/src/cmpilr.h	Tue Jun 12 17:44:58 2007 -0600
     8.3 @@ -28,15 +28,17 @@
     8.4  
     8.5  typedef struct _CMPIResourceFT {
     8.6     int (*load)();
     8.7 -   int (*unload)(CMPIBoolean terminating);
     8.8 +   int (*unload)();
     8.9     int (*beginEnum)(void **resList, CMPIStatus *status);
    8.10     void (*endEnum)(void* resList);
    8.11     int (*getNext)(void* resList, void **res, CMPIStatus *status);
    8.12 -   int (*get)(void* resList, void** res, CMPIStatus *status);
    8.13 +   int (*get)(void* resList, const CMPIObjectPath *res_key,
    8.14 +              void** res, CMPIStatus *status);
    8.15     void (*release)(void* res);
    8.16     int (*add)(void** resList, void* res, CMPIStatus *status);
    8.17     int (*delete)(void** resList, void* res, CMPIStatus *status);
    8.18 -   int (*modify)(void** resList, void* res, CMPIStatus *status);
    8.19 +   int (*modify)(void** resList, void* target_res,
    8.20 +                 void *modified_res, CMPIStatus *status);
    8.21     int (*res2inst)(void* res, CMPIInstance* inst, CMPIStatus *status);
    8.22     int (*inst2res)(CMPIInstance* inst, void** res, CMPIStatus *status);
    8.23  } CMPIResourceFT;