os-cmpi-xen
changeset 102:1903faaf4d37
Fixed VirtualSystemManagementService.DefineSystem and AddResourceSetting to work with xen-unstable/3.0.5
Signed-off-by: Jim Fehlig <jfehlig@novell.com>
Signed-off-by: Jim Fehlig <jfehlig@novell.com>
author | Jim Fehlig <jfehlig@novell.com> |
---|---|
date | Mon Apr 30 10:27:59 2007 -0600 (2007-04-30) |
parents | e3a930759ffc |
children | fa1ca0490794 |
files | ChangeLog src/Xen_VirtualSystemManagementService.c |
line diff
1.1 --- a/ChangeLog Thu Apr 19 16:00:52 2007 -0600 1.2 +++ b/ChangeLog Mon Apr 30 10:27:59 2007 -0600 1.3 @@ -1,3 +1,9 @@ 1.4 +------------------------------------------------------------------- 1.5 +Mon Apr 30 10:25:14 MDT 2007 - jfehlig@novell.com 1.6 + 1.7 + - Fixed VirtualSystemManagementService.DefineSystem and 1.8 + AddResourceSetting to work with xen-unstable/3.0.5 1.9 + 1.10 ------------------------------------------------------------------- 1.11 Thu Apr 19 15:57:27 MDT 2007 - jfehlig@novell.com 1.12
2.1 --- a/src/Xen_VirtualSystemManagementService.c Thu Apr 19 16:00:52 2007 -0600 2.2 +++ b/src/Xen_VirtualSystemManagementService.c Mon Apr 30 10:27:59 2007 -0600 2.3 @@ -34,6 +34,8 @@ 2.4 #include <xen_vm.h> 2.5 #include <xen_vif.h> 2.6 #include <xen_vbd.h> 2.7 +#include <xen_vdi.h> 2.8 +#include <xen_sr.h> 2.9 #include <xen_console.h> 2.10 #include <xen_vm_metrics.h> 2.11 #include <xen_string_string_map.h> 2.12 @@ -103,7 +105,7 @@ static int proc_rasd2vmconfig(CMPIInstan 2.13 static int mem_rasd2vmconfig(CMPIInstance *instance, xen_vm_record *vm_rec, 2.14 CMPIStatus *status); 2.15 static int disk_rasd2vmconfig(CMPIInstance *instance, xen_vbd_record **vbd_rec, 2.16 - CMPIStatus *status); 2.17 + xen_vdi_record **vdi_rec, CMPIStatus *status); 2.18 static int nic_rasd2vmconfig(CMPIInstance *instance, xen_vif_record **vif_rec, 2.19 CMPIStatus *status); 2.20 static int con_rasd2vmconfig(CMPIInstance *instance, xen_console_record *con_rec, 2.21 @@ -1148,10 +1150,12 @@ static int create_vm(CMPIInstance* vsSet 2.22 CMPIObjectPath *objectpath; 2.23 char *settingclassname; 2.24 xen_vm_record *vm_rec; 2.25 + xen_vdi_record_set *vdis = NULL; 2.26 xen_vbd_record_set *vbds = NULL; 2.27 xen_vif_record_set *vifs = NULL; 2.28 xen_console_record *con_rec = NULL; 2.29 xen_vm vm = NULL; 2.30 + xen_sr_set *srs = NULL; 2.31 int i; 2.32 int ccode; 2.33 char error_msg[XEN_UTILS_ERROR_BUF_LEN]; 2.34 @@ -1253,11 +1257,13 @@ static int create_vm(CMPIInstance* vsSet 2.35 _SBLIM_TRACE(2,("--- adding Xen_DiskSettingData to configuration")); 2.36 2.37 xen_vbd_record *vbd_rec; 2.38 - if (!disk_rasd2vmconfig(instance, &vbd_rec, status)) { 2.39 + xen_vdi_record *vdi_rec; 2.40 + if (!disk_rasd2vmconfig(instance, &vbd_rec, &vdi_rec, status)) { 2.41 _SBLIM_TRACE(1,("--- Error parsing disk settings")); 2.42 goto Error; 2.43 } 2.44 2.45 + ADD_DEVICE_TO_LIST(vdis, vdi_rec, xen_vdi_record); 2.46 ADD_DEVICE_TO_LIST(vbds, vbd_rec, xen_vbd_record); 2.47 } 2.48 else if (strcmp(settingclassname,"Xen_NetworkPortSettingData") == 0) { 2.49 @@ -1299,21 +1305,57 @@ static int create_vm(CMPIInstance* vsSet 2.50 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED, error_msg); 2.51 goto Error; 2.52 } 2.53 - 2.54 + 2.55 + /* Create devices. Need a Storage Repository (sr) for VDI. */ 2.56 xen_vm_record_opt vm_record_opt = 2.57 { 2.58 .u.handle = vm 2.59 }; 2.60 2.61 + if (!xen_sr_get_by_name_label(session->xen, &srs, "Local")) { 2.62 + XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen); 2.63 + _SBLIM_TRACE(1,("--- xen_sr_get_by_name_label failed: %s", error_msg)); 2.64 + CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED, error_msg); 2.65 + goto Error; 2.66 + } 2.67 + assert(srs->size == 1); 2.68 + 2.69 + xen_sr_record_opt sr_record = 2.70 + { 2.71 + .u.handle = srs->contents[0] 2.72 + }; 2.73 + 2.74 /* Add all of the virutal block devices. */ 2.75 - for (i = 0; i < vbds->size; i++) { 2.76 + for (i = 0; i < vdis->size; i++) { 2.77 2.78 + xen_vdi_record *vdi_rec = vdis->contents[i]; 2.79 + vdi_rec->sr = &sr_record; 2.80 + xen_vdi new_vdi; 2.81 + ccode = xen_vdi_create(session->xen, &new_vdi, vdi_rec); 2.82 + /* Set sr field of vdi record to NULL so it is not freed */ 2.83 + vdi_rec->sr = NULL; 2.84 + if (!ccode) 2.85 + { 2.86 + XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen); 2.87 + _SBLIM_TRACE(1,("--- xen_vdi_create failed: %s", error_msg)); 2.88 + CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED, error_msg); 2.89 + goto Error; 2.90 + } 2.91 + 2.92 + xen_vdi_record_opt vdi_record_opt = 2.93 + { 2.94 + .u.handle = new_vdi 2.95 + }; 2.96 + 2.97 xen_vbd_record *vbd_rec = vbds->contents[i]; 2.98 vbd_rec->vm = &vm_record_opt; 2.99 + vbd_rec->vdi = &vdi_record_opt; 2.100 xen_vbd new_vbd; 2.101 ccode = xen_vbd_create(session->xen, &new_vbd, vbd_rec); 2.102 - /* Set vm field of vbd record to NULL so it is not freed */ 2.103 + /* Set vm and vdi fields of vbd record to NULL so they are not freed */ 2.104 vbd_rec->vm = NULL; 2.105 + vbd_rec->vdi = NULL; 2.106 + xen_vdi_free(new_vdi); 2.107 if (!ccode) 2.108 { 2.109 XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen); 2.110 @@ -1360,8 +1402,10 @@ static int create_vm(CMPIInstance* vsSet 2.111 } 2.112 2.113 xen_console_record_free(con_rec); 2.114 + xen_vif_record_set_free(vifs); 2.115 xen_vbd_record_set_free(vbds); 2.116 - xen_vif_record_set_free(vifs); 2.117 + xen_vdi_record_set_free(vdis); 2.118 + xen_sr_set_free(srs); 2.119 xen_vm_record_free(vm_rec); 2.120 2.121 *result = vm; 2.122 @@ -1377,8 +1421,10 @@ static int create_vm(CMPIInstance* vsSet 2.123 xen_vm_free(vm); 2.124 } 2.125 xen_console_record_free(con_rec); 2.126 + xen_vif_record_set_free(vifs); 2.127 xen_vbd_record_set_free(vbds); 2.128 - xen_vif_record_set_free(vifs); 2.129 + xen_vdi_record_set_free(vdis); 2.130 + xen_sr_set_free(srs); 2.131 xen_vm_record_free(vm_rec); 2.132 *result = NULL; 2.133 2.134 @@ -1487,18 +1533,62 @@ static int add_resource_to_vm(xen_vm_rec 2.135 _SBLIM_TRACE(2,("--- adding Xen_DiskSettingData to configuration")); 2.136 2.137 xen_vbd_record *vbd_rec; 2.138 - if (!disk_rasd2vmconfig(sourceSettingInst, &vbd_rec, status)) { 2.139 + xen_vdi_record *vdi_rec; 2.140 + if (!disk_rasd2vmconfig(sourceSettingInst, &vbd_rec, &vdi_rec, status)) { 2.141 /* status set in disk_rasd2vmconfig */ 2.142 _SBLIM_TRACE(1,("--- Error parsing disk settings")); 2.143 return 0; 2.144 } 2.145 2.146 + xen_sr_set *srs; 2.147 + if (!xen_sr_get_by_name_label(session->xen, &srs, "Local")) { 2.148 + XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen); 2.149 + _SBLIM_TRACE(1,("--- xen_sr_get_by_name_label failed: %s", error_msg)); 2.150 + CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED, error_msg); 2.151 + xen_vbd_record_free(vbd_rec); 2.152 + xen_vdi_record_free(vdi_rec); 2.153 + return 0; 2.154 + } 2.155 + assert(srs->size == 1); 2.156 + 2.157 + xen_sr_record_opt sr_record = 2.158 + { 2.159 + .u.handle = srs->contents[0] 2.160 + }; 2.161 + 2.162 + vdi_rec->sr = &sr_record; 2.163 + xen_vdi new_vdi; 2.164 + ccode = xen_vdi_create(session->xen, &new_vdi, vdi_rec); 2.165 + /* Set sr field of vdi record to NULL so it is not freed */ 2.166 + vdi_rec->sr = NULL; 2.167 + if (!ccode) 2.168 + { 2.169 + XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen); 2.170 + _SBLIM_TRACE(1,("--- xen_vdi_create failed: %s", error_msg)); 2.171 + CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_FAILED, error_msg); 2.172 + xen_sr_set_free(srs); 2.173 + xen_vbd_record_free(vbd_rec); 2.174 + xen_vdi_record_free(vdi_rec); 2.175 + return 0; 2.176 + } 2.177 + 2.178 + xen_vdi_record_opt vdi_record_opt = 2.179 + { 2.180 + .u.handle = new_vdi 2.181 + }; 2.182 + 2.183 vbd_rec->vm = &vm_record_opt; 2.184 + vbd_rec->vdi = &vdi_record_opt; 2.185 xen_vbd new_vbd; 2.186 ccode = xen_vbd_create(session->xen, &new_vbd, vbd_rec); 2.187 - /* Set vm field of vbd record to NULL so it is not freed */ 2.188 + /* Set vm and vdi fields of vbd record to NULL so they are not freed */ 2.189 vbd_rec->vm = NULL; 2.190 + vbd_rec->vdi = NULL; 2.191 + /* Free allocated objects. */ 2.192 + xen_vdi_free(new_vdi); 2.193 + xen_sr_set_free(srs); 2.194 xen_vbd_record_free(vbd_rec); 2.195 + xen_vdi_record_free(vdi_rec); 2.196 if (!ccode) 2.197 { 2.198 XEN_UTILS_GET_ERROR_STRING(error_msg, session->xen); 2.199 @@ -1517,7 +1607,7 @@ static int add_resource_to_vm(xen_vm_rec 2.200 _SBLIM_TRACE(2,("--- adding Xen_NetworkPortSettingData to configuration")); 2.201 xen_vif_record *vif_rec; 2.202 if (!nic_rasd2vmconfig(sourceSettingInst, &vif_rec, status)) { 2.203 - /* status set in disk_rasd2vmconfig */ 2.204 + /* status set in nic_rasd2vmconfig */ 2.205 _SBLIM_TRACE(1,("--- Error parsing network port settings")); 2.206 return 0; 2.207 } 2.208 @@ -1554,20 +1644,14 @@ static int add_resource_to_vm(xen_vm_rec 2.209 2.210 static void remove_vm(xen_vm vm) 2.211 { 2.212 - xen_vbd_set *vbds; 2.213 - xen_vif_set *vifs; 2.214 - int i; 2.215 - 2.216 - if (xen_vm_get_vbds(session->xen, &vbds, vm)) { 2.217 - for (i = 0; i < vbds->size; i++) 2.218 - xen_vbd_destroy(session->xen, vbds->contents[i]); 2.219 - } 2.220 - 2.221 - if (xen_vm_get_vifs(session->xen, &vifs, vm)) { 2.222 - for (i = 0; i < vifs->size; i++) 2.223 - xen_vif_destroy(session->xen, vifs->contents[i]); 2.224 - } 2.225 - 2.226 + /* 2.227 + * TODO: 2.228 + * We want to destroy the VM, so reset any previous failures on the 2.229 + * session object. But do we want to be touching internal fields in 2.230 + * this manner? Revisit once we move to the new resource abstraction 2.231 + * interface. 2.232 + */ 2.233 + session->xen->ok = true; 2.234 xen_vm_destroy(session->xen, vm); 2.235 } 2.236 2.237 @@ -1796,7 +1880,7 @@ static int vssd2xenconfig(CMPIInstance * 2.238 return 1; 2.239 } 2.240 2.241 -// Look for vcpus_number in the metrics structure. 2.242 + 2.243 static int proc_rasd2vmconfig(CMPIInstance *proc_rasd, xen_vm_record *vm_rec, 2.244 CMPIStatus *status) 2.245 { 2.246 @@ -1808,8 +1892,12 @@ static int proc_rasd2vmconfig(CMPIInstan 2.247 * TODO: 2.248 * 1. Handle defaults if processors not specified. 2.249 * 2. CPU weights and other scheduling parameters? 2.250 + * 3. Handle VM.vcpus_max properly. 0 is not good so 2.251 + * we'll set it to same value as number of vcpus set 2.252 + * in VirtualQuantity for now. 2.253 */ 2.254 vm_rec->vcpus_at_startup = propertyvalue.value.uint64; 2.255 + vm_rec->vcpus_max = propertyvalue.value.uint64; 2.256 return 1; 2.257 } 2.258 2.259 @@ -1821,31 +1909,41 @@ static int mem_rasd2vmconfig(CMPIInstanc 2.260 CMPIStatus *status) 2.261 { 2.262 CMPIData propertyvalue; 2.263 + 2.264 + propertyvalue = CMGetProperty(mem_rasd, "AllocationUnits", status); 2.265 + if ((status->rc != CMPI_RC_OK) || CMIsNullValue(propertyvalue)) { 2.266 + return 0; 2.267 + } 2.268 + 2.269 + char *units = CMGetCharPtr(propertyvalue.value.string); 2.270 2.271 propertyvalue = CMGetProperty(mem_rasd, "VirtualQuantity", status); 2.272 - if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue)) { 2.273 - /* 2.274 - * TODO: 2.275 - * 1. Handle defaults if memory is not specified. 2.276 - * 2. What is semantics of these fields? For now 2.277 - * set them all to the requested value. 2.278 - */ 2.279 - vm_rec->memory_static_max = propertyvalue.value.uint64; 2.280 - vm_rec->memory_dynamic_max = propertyvalue.value.uint64; 2.281 - vm_rec->memory_static_min = propertyvalue.value.uint64; 2.282 - vm_rec->memory_dynamic_min = propertyvalue.value.uint64; 2.283 - 2.284 - return 1; 2.285 + if ((status->rc != CMPI_RC_OK) || CMIsNullValue(propertyvalue)) { 2.286 + return 0; 2.287 } 2.288 2.289 - return 0; 2.290 + uint64_t mem_size = propertyvalue.value.uint64; 2.291 + if (strstr(units, "Mega") || strstr(units, "M")) 2.292 + mem_size = mem_size * 1024 * 1024; 2.293 + 2.294 + /* 2.295 + * TODO: 2.296 + * 1. Handle defaults if memory is not specified. 2.297 + */ 2.298 + vm_rec->memory_static_max = mem_size; 2.299 + vm_rec->memory_dynamic_max = mem_size; 2.300 + vm_rec->memory_dynamic_min = mem_size; 2.301 + 2.302 + return 1; 2.303 } 2.304 2.305 2.306 static int disk_rasd2vmconfig(CMPIInstance *disk_rasd, xen_vbd_record **vbd_rec, 2.307 - CMPIStatus *status) 2.308 + xen_vdi_record **vdi_rec, CMPIStatus *status) 2.309 { 2.310 CMPIData propertyvalue; 2.311 + char *tmp_str = NULL; 2.312 + xen_string_string_map *vdi_params = NULL; 2.313 2.314 propertyvalue = CMGetProperty(disk_rasd, "DiskConfigInfo", status); 2.315 if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue)) { 2.316 @@ -1855,24 +1953,47 @@ static int disk_rasd2vmconfig(CMPIInstan 2.317 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERROR_SYSTEM, "Unable to malloc memory"); 2.318 return 0; 2.319 } 2.320 + 2.321 + *vdi_rec = xen_vdi_record_alloc(); 2.322 + if (*vdi_rec == NULL) { 2.323 + _SBLIM_TRACE(1,("--- Cannot malloc memory for virtual disk image")); 2.324 + CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERROR_SYSTEM, "Unable to malloc memory"); 2.325 + goto Error; 2.326 + } 2.327 2.328 /* Extract the image, dev and mode params from the DiskConfigInfo string */ 2.329 char *tok; 2.330 char *next_tok; 2.331 - char *string = strdup(CMGetCharPtr(propertyvalue.value.string)); 2.332 - tok = strtok_r(string, ",", &next_tok); 2.333 + tmp_str = strdup(CMGetCharPtr(propertyvalue.value.string)); 2.334 + tok = strtok_r(tmp_str, ",", &next_tok); 2.335 if (tok == NULL) { 2.336 _SBLIM_TRACE(1,("--- Malformed DiskConfigInfo property in disk setting data")); 2.337 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "Invalid disk setting data"); 2.338 - free(string); 2.339 + goto Error; 2.340 + } 2.341 + 2.342 + vdi_params = xen_string_string_map_alloc(1); 2.343 + if (vdi_params == NULL) { 2.344 + _SBLIM_TRACE(1,("--- Cannot malloc memory for VDI options")); 2.345 + CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERROR_SYSTEM, "Unable to malloc memory"); 2.346 goto Error; 2.347 } 2.348 -// (*vbd_rec)->image = strdup(tok); VDI<->BBD issue 2.349 + 2.350 + vdi_params->contents[0].key = strdup("location"); 2.351 + vdi_params->contents[0].val = strdup(tok); 2.352 + (*vdi_rec)->other_config = vdi_params; 2.353 + 2.354 + /* 2.355 + * TODO: 2.356 + * Need to handle specifying some of the VDI fields. For now 2.357 + * we'll hardcode to something reasonable. 2.358 + */ 2.359 + (*vdi_rec)->type = XEN_VDI_TYPE_SYSTEM; 2.360 + (*vdi_rec)->sharable = false; 2.361 2.362 if ((tok = strtok_r(NULL, ",", &next_tok)) == NULL) { 2.363 _SBLIM_TRACE(1,("--- Malformed DiskConfigInfo property in disk setting data")); 2.364 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "Invalid disk setting data"); 2.365 - free(string); 2.366 goto Error; 2.367 } 2.368 (*vbd_rec)->device = strdup(tok); 2.369 @@ -1880,16 +2001,25 @@ static int disk_rasd2vmconfig(CMPIInstan 2.370 if ((tok = strtok_r(NULL, ",", &next_tok)) == NULL) { 2.371 _SBLIM_TRACE(1,("--- Malformed DiskConfigInfo property in disk setting data")); 2.372 CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "Invalid disk setting data"); 2.373 - free(string); 2.374 goto Error; 2.375 } 2.376 - if (strcmp(tok, "w") == 0) 2.377 + if (strcmp(tok, "w") == 0) { 2.378 (*vbd_rec)->mode = XEN_VBD_MODE_RW; 2.379 - else 2.380 + (*vdi_rec)->read_only = false; 2.381 + } 2.382 + else { 2.383 (*vbd_rec)->mode = XEN_VBD_MODE_RO; 2.384 + (*vdi_rec)->read_only = true; 2.385 + } 2.386 + 2.387 + /* 2.388 + * TODO: 2.389 + * 1. Handle specifying type. For now just say its a disk. 2.390 + */ 2.391 + (*vbd_rec)->type = XEN_VBD_TYPE_DISK; 2.392 2.393 - free(string); 2.394 - //_SBLIM_TRACE(2,("--- uname = %s", (*vbd_rec)->image)); 2.395 + free(tmp_str); 2.396 + _SBLIM_TRACE(2,("--- uname = %s", vdi_params->contents[0].val)); 2.397 _SBLIM_TRACE(2,("--- dev = %s", (*vbd_rec)->device)); 2.398 _SBLIM_TRACE(2,("--- mode = %s", 2.399 (*vbd_rec)->mode == XEN_VBD_MODE_RW ? "RW" : "RO")); 2.400 @@ -1898,9 +2028,12 @@ static int disk_rasd2vmconfig(CMPIInstan 2.401 } 2.402 2.403 Error: 2.404 + free(tmp_str); 2.405 /* frees fields as well */ 2.406 xen_vbd_record_free(*vbd_rec); 2.407 *vbd_rec = NULL; 2.408 + xen_vdi_record_free(*vdi_rec); 2.409 + *vdi_rec = NULL; 2.410 2.411 return 0; 2.412 }