ia64/xen-unstable
changeset 14465:4b9150e9ecfd
[ioemu] Cleanup media change code.
Signed-off-by: Christian Limpach <Christian.Limpach@xensource.com>
Signed-off-by: Christian Limpach <Christian.Limpach@xensource.com>
author | Christian Limpach <Christian.Limpach@xensource.com> |
---|---|
date | Mon Mar 19 11:15:28 2007 +0000 (2007-03-19) |
parents | 066b66ce1f98 |
children | 9b9aa9d6603b |
files | tools/ioemu/xenstore.c |
line diff
1.1 --- a/tools/ioemu/xenstore.c Mon Mar 19 11:09:57 2007 +0000 1.2 +++ b/tools/ioemu/xenstore.c Mon Mar 19 11:15:28 2007 +0000 1.3 @@ -18,7 +18,7 @@ 1.4 #include <fcntl.h> 1.5 1.6 static struct xs_handle *xsh = NULL; 1.7 -static char *hd_filename[MAX_DISKS]; 1.8 +static char *media_filename[MAX_DISKS]; 1.9 static QEMUTimer *insert_timer = NULL; 1.10 1.11 #define UWAIT_MAX (30*1000000) /* thirty seconds */ 1.12 @@ -45,10 +45,10 @@ static void insert_media(void *opaque) 1.13 int i; 1.14 1.15 for (i = 0; i < MAX_DISKS; i++) { 1.16 - if (hd_filename[i]) { 1.17 - do_change(bs_table[i]->device_name, hd_filename[i]); 1.18 - free(hd_filename[i]); 1.19 - hd_filename[i] = NULL; 1.20 + if (media_filename[i] && bs_table[i]) { 1.21 + do_change(bs_table[i]->device_name, media_filename[i]); 1.22 + free(media_filename[i]); 1.23 + media_filename[i] = NULL; 1.24 } 1.25 } 1.26 } 1.27 @@ -87,7 +87,7 @@ void xenstore_parse_domain_config(int do 1.28 unsigned int len, num, hd_index; 1.29 1.30 for(i = 0; i < MAX_DISKS; i++) 1.31 - hd_filename[i] = NULL; 1.32 + media_filename[i] = NULL; 1.33 1.34 xsh = xs_daemon_open(); 1.35 if (xsh == NULL) { 1.36 @@ -133,19 +133,12 @@ void xenstore_parse_domain_config(int do 1.37 continue; 1.38 free(type); 1.39 type = xs_read(xsh, XBT_NULL, buf, &len); 1.40 - /* read params to get the patch of the image -- read it last 1.41 - * so that we have its path in buf when setting up the 1.42 - * watch */ 1.43 if (pasprintf(&buf, "%s/params", bpath) == -1) 1.44 continue; 1.45 free(params); 1.46 params = xs_read(xsh, XBT_NULL, buf, &len); 1.47 if (params == NULL) 1.48 continue; 1.49 - if (params[0]) { 1.50 - hd_filename[hd_index] = params; /* strdup() */ 1.51 - params = NULL; /* don't free params on re-use */ 1.52 - } 1.53 /* 1.54 * check if device has a phantom vbd; the phantom is hooked 1.55 * to the frontend device (for ease of cleanup), so lookup 1.56 @@ -156,35 +149,32 @@ void xenstore_parse_domain_config(int do 1.57 continue; 1.58 free(fpath); 1.59 fpath = xs_read(xsh, XBT_NULL, buf, &len); 1.60 - if (fpath != NULL) { 1.61 + if (fpath) { 1.62 if (pasprintf(&buf, "%s/dev", fpath) == -1) 1.63 continue; 1.64 + free(params); 1.65 params = xs_read(xsh, XBT_NULL, buf , &len); 1.66 - if (params != NULL) { 1.67 - free(hd_filename[hd_index]); 1.68 - hd_filename[hd_index] = params; 1.69 - params = NULL; /* don't free params on re-use */ 1.70 + if (params) { 1.71 /* 1.72 * wait for device, on timeout silently fail because we will 1.73 * fail to open below 1.74 */ 1.75 - waitForDevice(hd_filename[hd_index]); 1.76 + waitForDevice(params); 1.77 } 1.78 } 1.79 + 1.80 bs_table[hd_index] = bdrv_new(dev); 1.81 - /* re-establish buf */ 1.82 - if (pasprintf(&buf, "%s/params", bpath) == -1) 1.83 - continue; 1.84 /* check if it is a cdrom */ 1.85 if (type && !strcmp(type, "cdrom")) { 1.86 bdrv_set_type_hint(bs_table[hd_index], BDRV_TYPE_CDROM); 1.87 - xs_watch(xsh, buf, dev); 1.88 + if (pasprintf(&buf, "%s/params", bpath) != -1) 1.89 + xs_watch(xsh, buf, dev); 1.90 } 1.91 - if (hd_filename[hd_index]) { 1.92 - if (bdrv_open(bs_table[hd_index], hd_filename[hd_index], 1.93 - 0 /* snapshot */) < 0) 1.94 + /* open device now if media present */ 1.95 + if (params[0]) { 1.96 + if (bdrv_open(bs_table[hd_index], params, 0 /* snapshot */) < 0) 1.97 fprintf(stderr, "qemu: could not open hard disk image '%s'\n", 1.98 - hd_filename[hd_index]); 1.99 + params); 1.100 } 1.101 } 1.102 1.103 @@ -347,13 +337,13 @@ void xenstore_process_event(void *opaque 1.104 1.105 do_eject(0, vec[XS_WATCH_TOKEN]); 1.106 bs_table[hd_index]->filename[0] = 0; 1.107 - if (hd_filename[hd_index]) { 1.108 - free(hd_filename[hd_index]); 1.109 - hd_filename[hd_index] = NULL; 1.110 + if (media_filename[hd_index]) { 1.111 + free(media_filename[hd_index]); 1.112 + media_filename[hd_index] = NULL; 1.113 } 1.114 1.115 if (image[0]) { 1.116 - hd_filename[hd_index] = strdup(image); 1.117 + media_filename[hd_index] = strdup(image); 1.118 xenstore_check_new_media_present(5000); 1.119 } 1.120