os-cmpi-xen
changeset 122:28e8c94e92de
Added xen_string_string_map utility function to xen_utils.
Signed-off-by: Jim Fehlig <jfehlig@novell.com>
Signed-off-by: Jim Fehlig <jfehlig@novell.com>
author | Jim Fehlig <jfehlig@novell.com> |
---|---|
date | Mon Jun 11 14:19:07 2007 -0600 (2007-06-11) |
parents | 4868ace2726b |
children | 3e8654ff41d1 |
files | src/Xen_ComputerSystemSettingData_Resource.c src/Xen_Disk.c src/Xen_DiskSettingData.c src/xen_utils.c src/xen_utils.h |
line diff
1.1 --- a/src/Xen_ComputerSystemSettingData_Resource.c Fri Jun 08 10:22:05 2007 -0600 1.2 +++ b/src/Xen_ComputerSystemSettingData_Resource.c Mon Jun 11 14:19:07 2007 -0600 1.3 @@ -165,7 +165,7 @@ int Xen_ComputerSystemSettingData_setIns 1.4 snprintf(inst_id, 1024, "Xen:%s", resource->name_label); 1.5 CMSetProperty(instance, "InstanceID",(CMPIValue *)inst_id, CMPI_chars); 1.6 // There must be an easier way of figuring out pv/hvm, but, until we figure that out, we will keep this - Raj 1.7 - if ((hvm_boot_order = xen_utils_get_value_from_map(resource->hvm_boot_params, "order"))) { 1.8 + if ((hvm_boot_order = xen_utils_get_from_string_string_map(resource->hvm_boot_params, "order"))) { 1.9 /* HVM settings */ 1.10 CMSetProperty(instance, "VirtualSystemType", (CMPIValue *)"hvm-3.0-unknown", CMPI_chars); 1.11 CMSetProperty(instance, "BootOrder", (CMPIValue *)hvm_boot_order, CMPI_chars);
2.1 --- a/src/Xen_Disk.c Fri Jun 08 10:22:05 2007 -0600 2.2 +++ b/src/Xen_Disk.c Mon Jun 11 14:19:07 2007 -0600 2.3 @@ -367,7 +367,7 @@ static int res2inst(void *res, CMPIInsta 2.4 char *image; 2.5 xen_string_string_map *vdi_params = NULL; 2.6 if (xen_vdi_get_other_config(session->xen, &vdi_params, vdi_rec_opt->u.handle)) { 2.7 - if ((image = xen_utils_get_value_from_map(vdi_params, "location"))) { 2.8 + if ((image = xen_utils_get_from_string_string_map(vdi_params, "location"))) { 2.9 CMSetProperty(inst, "Device",(CMPIValue *)image, CMPI_chars); 2.10 snprintf(buf, MAX_INSTANCEID_LEN, "%s,%s,%s", 2.11 image, vbd_rec->device, mode);
3.1 --- a/src/Xen_DiskSettingData.c Fri Jun 08 10:22:05 2007 -0600 3.2 +++ b/src/Xen_DiskSettingData.c Mon Jun 11 14:19:07 2007 -0600 3.3 @@ -350,8 +350,10 @@ static int res2inst(void *res, CMPIInsta 3.4 xen_vdi_record_opt *vdi_rec_opt = vbd_rec->vdi; 3.5 char *image; 3.6 xen_string_string_map *vdi_params = NULL; 3.7 - if (xen_vdi_get_other_config(session->xen, &vdi_params, vdi_rec_opt->u.handle)) { 3.8 - if ((image = xen_utils_get_value_from_map(vdi_params, "location"))) { 3.9 + if (xen_vdi_get_other_config(session->xen, 3.10 + &vdi_params, vdi_rec_opt->u.handle)) { 3.11 + if ((image = 3.12 + xen_utils_get_from_string_string_map(vdi_params, "location"))) { 3.13 snprintf(buf, MAX_INSTANCEID_LEN, "%s,%s,%s", 3.14 image, vbd_rec->device, mode); 3.15 CMSetProperty(inst, "DiskConfigInfo",(CMPIValue *)buf, CMPI_chars); 3.16 @@ -400,7 +402,8 @@ static int inst2res(CMPIInstance *inst, 3.17 return 0; 3.18 } 3.19 3.20 - if (!xen_vbd_get_record(session->xen, (xen_vbd_record **)res, (xen_vbd)uuid)) { 3.21 + if (!xen_vbd_get_record(session->xen, 3.22 + (xen_vbd_record **)res, (xen_vbd)uuid)) { 3.23 _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, 3.24 ("--- xen_vbd_get_record failed:")); 3.25 _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
4.1 --- a/src/xen_utils.c Fri Jun 08 10:22:05 2007 -0600 4.2 +++ b/src/xen_utils.c Mon Jun 11 14:19:07 2007 -0600 4.3 @@ -689,14 +689,14 @@ int xen_utils_is_domain_active(xen_utils 4.4 4.5 4.6 /* 4.7 - * Extract a value with given key. 4.8 - * Returns pointer to value on success, NULL on failure. 4.9 - * 4.10 -*/ 4.11 -char *xen_utils_get_value_from_map(xen_string_string_map *map, const char *key) 4.12 + * Get value of key from map. 4.13 + * Returns pointer to value on success, NULL if key does not exist in map. 4.14 + */ 4.15 +char *xen_utils_get_from_string_string_map(xen_string_string_map *map, 4.16 + const char *key) 4.17 { 4.18 int i = 0; 4.19 - // Make sure you have a good value 4.20 + 4.21 if(!map) 4.22 return NULL; 4.23 4.24 @@ -715,6 +715,51 @@ char *xen_utils_get_value_from_map(xen_s 4.25 4.26 4.27 /* 4.28 + * Add key/val to map. If map contains key, update value for that key. 4.29 + * Returns non-zero on success, 0 on failure. On failure, contens of map 4.30 + * is unchanged. 4.31 + */ 4.32 +int xen_utils_add_to_string_string_map(const char *key, const char *val, 4.33 + xen_string_string_map **map) 4.34 +{ 4.35 + int i; 4.36 + 4.37 + if (*map == NULL) { 4.38 + *map = xen_string_string_map_alloc(1); 4.39 + if (*map == NULL) 4.40 + return 0; 4.41 + 4.42 + (*map)->size = 1; 4.43 + (*map)->contents[0].key = strdup(key); 4.44 + (*map)->contents[0].val = strdup(val); 4.45 + return 1; 4.46 + } 4.47 + 4.48 + /* Map is not empty. Does key already exist? */ 4.49 + for (i = 0; i < (*map)->size; i++) { 4.50 + if (strcmp((*map)->contents[i].key, key) == 0) { 4.51 + free((*map)->contents[i].val); 4.52 + (*map)->contents[i].val = strdup(val); 4.53 + return 1; 4.54 + } 4.55 + } 4.56 + 4.57 + /* Grow the map and add the new entry */ 4.58 + int new_len = sizeof(xen_string_string_map) + 4.59 + (((*map)->size + 1) * sizeof(xen_string_string_map_contents)); 4.60 + *map = realloc(*map, new_len); 4.61 + if (*map == NULL) 4.62 + return 0; 4.63 + 4.64 + (*map)->contents[(*map)->size].key = strdup(key); 4.65 + (*map)->contents[(*map)->size].val = strdup(val); 4.66 + (*map)->size++; 4.67 + 4.68 + return 1; 4.69 +} 4.70 + 4.71 + 4.72 +/* 4.73 * Trace the error descriptions found in xen session object. 4.74 * This routine uses _sblim_trace function in cmpitrace interface 4.75 * for actual tracing. Output is to a location specified in the
5.1 --- a/src/xen_utils.h Fri Jun 08 10:22:05 2007 -0600 5.2 +++ b/src/xen_utils.h Mon Jun 11 14:19:07 2007 -0600 5.3 @@ -307,10 +307,19 @@ int xen_utils_is_domain_active(xen_utils 5.4 5.5 5.6 /* 5.7 - * Extract a value with given key. 5.8 - * Returns pointer to value on success, NULL on failure. 5.9 -*/ 5.10 -char *xen_utils_get_value_from_map(xen_string_string_map *map, const char *key); 5.11 + * Get value of key from map. 5.12 + * Returns pointer to value on success, NULL if key does not exist in map. 5.13 + */ 5.14 +char *xen_utils_get_from_string_string_map(xen_string_string_map *map, 5.15 + const char *key); 5.16 + 5.17 + 5.18 +/* 5.19 + * Add key/val to map. If map contains key, update value for that key. 5.20 + * Returns non-zero on success, 0 on failure. On failure, map is unchanged. 5.21 + */ 5.22 +int xen_utils_add_to_string_string_map(const char *key, const char *val, 5.23 + xen_string_string_map **map); 5.24 5.25 5.26 /*