ia64/xen-unstable

changeset 14187:3379f667c3a6

Use stat to poll on phantom device until it becomes ready

Signed-off by Wim Colgate <wim@xensource.com>
author Wim Colgate <wim@xensource.com>
date Wed Feb 28 12:35:36 2007 -0800 (2007-02-28)
parents d66dff09338a
children b703aa29424f
files tools/ioemu/xenstore.c
line diff
     1.1 --- a/tools/ioemu/xenstore.c	Wed Feb 28 18:15:42 2007 +0000
     1.2 +++ b/tools/ioemu/xenstore.c	Wed Feb 28 12:35:36 2007 -0800
     1.3 @@ -16,6 +16,9 @@ static struct xs_handle *xsh = NULL;
     1.4  static char *hd_filename[MAX_DISKS];
     1.5  static QEMUTimer *insert_timer = NULL;
     1.6  
     1.7 +#define UWAIT_MAX (30*1000000) /* thirty seconds */
     1.8 +#define UWAIT     (100000)     /* 1/10th second  */
     1.9 +
    1.10  static int pasprintf(char **buf, const char *fmt, ...)
    1.11  {
    1.12      va_list ap;
    1.13 @@ -53,32 +56,20 @@ void xenstore_check_new_media_present(in
    1.14      qemu_mod_timer(insert_timer, qemu_get_clock(rt_clock) + timeout);
    1.15  }
    1.16  
    1.17 -static int waitForDevice(char *path, char *field, char *desired)
    1.18 +static void waitForDevice(char *fn)
    1.19  { 
    1.20 -    char *buf = NULL, *stat = NULL;
    1.21 -    unsigned int len;
    1.22 -    int val = 1;
    1.23 +    struct stat sbuf;
    1.24 +    int status;
    1.25 +    int uwait = UWAIT_MAX;
    1.26  
    1.27 -    /* loop until we find a value in xenstore, return 
    1.28 -     * if it was what we wanted, or not
    1.29 -     */
    1.30 -    while (1) {
    1.31 -        if (pasprintf(&buf, "%s/%s", path, field) == -1)
    1.32 -            goto done;
    1.33 -        free(stat);
    1.34 -        stat = xs_read(xsh, XBT_NULL, buf, &len);
    1.35 -        if (stat == NULL) {
    1.36 -            usleep(100000); /* 1/10th second, no path found */
    1.37 -        } else {
    1.38 -            val = strcmp(stat, desired);
    1.39 -            goto done;
    1.40 -        }
    1.41 -    }
    1.42 +    do {
    1.43 +        status = stat(fn, &sbuf);
    1.44 +        if (!status) break;
    1.45 +        usleep(UWAIT);
    1.46 +        uwait -= UWAIT;
    1.47 +    } while (uwait > 0);
    1.48  
    1.49 -done:
    1.50 -    free(stat);
    1.51 -    free(buf);
    1.52 -    return val;
    1.53 +    return;
    1.54  }
    1.55  
    1.56  void xenstore_parse_domain_config(int domid)
    1.57 @@ -161,11 +152,6 @@ void xenstore_parse_domain_config(int do
    1.58  	free(fpath);
    1.59          fpath = xs_read(xsh, XBT_NULL, buf, &len);
    1.60  	if (fpath != NULL) {
    1.61 -
    1.62 -            if (waitForDevice(fpath, "hotplug-status", "connected")) {
    1.63 -               continue;
    1.64 -            }
    1.65 -
    1.66  	    if (pasprintf(&buf, "%s/dev", fpath) == -1)
    1.67  	        continue;
    1.68              params = xs_read(xsh, XBT_NULL, buf , &len);
    1.69 @@ -173,6 +159,11 @@ void xenstore_parse_domain_config(int do
    1.70                  free(hd_filename[hd_index]);
    1.71                  hd_filename[hd_index] = params;
    1.72                  params = NULL;              /* don't free params on re-use */
    1.73 +                /* 
    1.74 +                 * wait for device, on timeout silently fail because we will 
    1.75 +                 * fail to open below
    1.76 +                 */
    1.77 +                waitForDevice(hd_filename[hd_index]);
    1.78              }
    1.79          }
    1.80  	bs_table[hd_index] = bdrv_new(dev);