ia64/xen-unstable

changeset 11748:a72fdb6a19a1

[BLKTAP] Blktapctrl: Add asynchronous watch on dom0 name entry for blktapctrl on startup. This patch cleans up the synchronisation issues between blktapctrl and xend at initialisation if the Dom0 entries have not yet been populated.

Signed-off-by: Julian Chesterfield <julian@xensource.com>
author jchesterfield@dhcp92.uk.xensource.com
date Thu Oct 05 10:55:13 2006 +0100 (2006-10-05)
parents ad926cc0a50e
children 2e58022889a5
files tools/blktap/drivers/blktapctrl.c tools/blktap/lib/blktaplib.h tools/blktap/lib/xenbus.c tools/blktap/lib/xs_api.c tools/blktap/lib/xs_api.h
line diff
     1.1 --- a/tools/blktap/drivers/blktapctrl.c	Thu Oct 05 10:09:25 2006 +0100
     1.2 +++ b/tools/blktap/drivers/blktapctrl.c	Thu Oct 05 10:55:13 2006 +0100
     1.3 @@ -669,6 +669,7 @@ int main(int argc, char *argv[])
     1.4  		goto open_failed;
     1.5  	}
     1.6  
     1.7 +
     1.8   retry:
     1.9  	/* Set up store connection and watch. */
    1.10  	h = xs_daemon_open();
    1.11 @@ -682,15 +683,14 @@ int main(int argc, char *argv[])
    1.12                  } else goto open_failed;
    1.13  	}
    1.14  	
    1.15 -	ret = add_blockdevice_probe_watch(h, "Domain-0");
    1.16 -	if (ret != 0) {
    1.17 +	ret = setup_probe_watch(h);
    1.18 +	if (ret < 0) {
    1.19  		DPRINTF("Failed adding device probewatch\n");
    1.20 -                if (count < MAX_ATTEMPTS) {
    1.21 -                        count++;
    1.22 -                        sleep(2);
    1.23 -                        xs_daemon_close(h);
    1.24 -                        goto retry;
    1.25 -                } else goto open_failed;
    1.26 +		xs_daemon_close(h);
    1.27 +		goto open_failed;
    1.28 +	} else {
    1.29 +		DPRINTF("Added probe %s\n", 
    1.30 +		       (ret ? "ASYNCHRONOUSLY":"SYNCHRONOUSLY"));
    1.31  	}
    1.32  
    1.33  	ioctl(ctlfd, BLKTAP_IOCTL_SETMODE, BLKTAP_MODE_INTERPOSE );
     2.1 --- a/tools/blktap/lib/blktaplib.h	Thu Oct 05 10:09:25 2006 +0100
     2.2 +++ b/tools/blktap/lib/blktaplib.h	Thu Oct 05 10:55:13 2006 +0100
     2.3 @@ -193,8 +193,8 @@ typedef struct msg_pid {
     2.4  #define CTLMSG_PID_RSP     10
     2.5  
     2.6  /* xenstore/xenbus: */
     2.7 -extern int add_blockdevice_probe_watch(struct xs_handle *h, 
     2.8 -                                       const char *domname);
     2.9 +#define DOMNAME "Domain-0"
    2.10 +int setup_probe_watch(struct xs_handle *h);
    2.11  int xs_fire_next_watch(struct xs_handle *h);
    2.12  
    2.13  
     3.1 --- a/tools/blktap/lib/xenbus.c	Thu Oct 05 10:09:25 2006 +0100
     3.2 +++ b/tools/blktap/lib/xenbus.c	Thu Oct 05 10:55:13 2006 +0100
     3.3 @@ -356,17 +356,12 @@ static void ueblktap_probe(struct xs_han
     3.4   *are created, we initalise the state and attach a disk.
     3.5   */
     3.6  
     3.7 -int add_blockdevice_probe_watch(struct xs_handle *h, const char *domname)
     3.8 +int add_blockdevice_probe_watch(struct xs_handle *h, const char *domid)
     3.9  {
    3.10 -	char *domid, *path;
    3.11 +	char *path;
    3.12  	struct xenbus_watch *vbd_watch;
    3.13  	int er;
    3.14  	
    3.15 -	domid = get_dom_domid(h, domname);
    3.16 -
    3.17 -	DPRINTF("%s: %s\n", 
    3.18 -		domname, (domid != NULL) ? domid : "[ not found! ]");
    3.19 -	
    3.20  	asprintf(&path, "/local/domain/%s/backend/tap", domid);
    3.21  	if (path == NULL) 
    3.22  		return -ENOMEM;
    3.23 @@ -385,3 +380,69 @@ int add_blockdevice_probe_watch(struct x
    3.24  	}
    3.25  	return 0;
    3.26  }
    3.27 +
    3.28 +/*
    3.29 + *Asynch callback to check for /local/domain/<DOMID>/name
    3.30 + */
    3.31 +void check_dom(struct xs_handle *h, struct xenbus_watch *w, 
    3.32 +	       const char *bepath_im) {
    3.33 +	char *domid = NULL;
    3.34 +
    3.35 +	domid = get_dom_domid(h);
    3.36 +	if (domid) {
    3.37 +		add_blockdevice_probe_watch(h, domid);
    3.38 +		free(domid);
    3.39 +		unregister_xenbus_watch(h, w);
    3.40 +	}
    3.41 +	return;	
    3.42 +}
    3.43 +
    3.44 +/*
    3.45 + *We must wait for xend to register /local/domain/<DOMID>
    3.46 + */
    3.47 +int watch_for_domid(struct xs_handle *h)
    3.48 +{
    3.49 +	struct xenbus_watch *domid_watch;
    3.50 +	char *path = NULL;
    3.51 +	int er;
    3.52 +
    3.53 +	asprintf(&path, "/local/domain");
    3.54 +	if (path == NULL) 
    3.55 +		return -ENOMEM;
    3.56 +
    3.57 +	domid_watch = (struct xenbus_watch *)malloc(sizeof(struct xenbus_watch));
    3.58 +	if (!domid_watch) {
    3.59 +		DPRINTF("ERROR: unable to malloc domid_watch [%s]\n", path);
    3.60 +		return -EINVAL;
    3.61 +	}	
    3.62 +	domid_watch->node     = path;
    3.63 +	domid_watch->callback = check_dom;
    3.64 +	er = register_xenbus_watch(h, domid_watch);
    3.65 +	if (er == 0) {
    3.66 +		DPRINTF("ERROR: adding vbd probe watch %s\n", path);
    3.67 +		return -EINVAL;
    3.68 +	}
    3.69 +	if (path == NULL) 
    3.70 +		return -ENOMEM;	
    3.71 +	return 1;
    3.72 +}
    3.73 +
    3.74 +int setup_probe_watch(struct xs_handle *h)
    3.75 +{
    3.76 +	char *domid = NULL, *path;
    3.77 +	int ret;
    3.78 +	
    3.79 +	domid = get_dom_domid(h);
    3.80 +
    3.81 +	if (!domid) {
    3.82 +                /*Asynchronous path*/
    3.83 +		ret = watch_for_domid(h);
    3.84 +		goto finish;
    3.85 +	} else {
    3.86 +		/*Synchronous path*/
    3.87 +		ret = add_blockdevice_probe_watch(h, domid);
    3.88 +		free(domid);
    3.89 +	}
    3.90 + finish:
    3.91 +	return ret;
    3.92 +}
     4.1 --- a/tools/blktap/lib/xs_api.c	Thu Oct 05 10:09:25 2006 +0100
     4.2 +++ b/tools/blktap/lib/xs_api.c	Thu Oct 05 10:55:13 2006 +0100
     4.3 @@ -165,7 +165,7 @@ int xs_exists(struct xs_handle *h, const
     4.4   * This assumes that the domain name we are looking for is unique. 
     4.5   * Name parameter Domain-0 
     4.6   */
     4.7 -char *get_dom_domid(struct xs_handle *h, const char *name)
     4.8 +char *get_dom_domid(struct xs_handle *h)
     4.9  {
    4.10  	char **e, *val, *domid = NULL;
    4.11  	unsigned int num, len;
    4.12 @@ -187,7 +187,7 @@ char *get_dom_domid(struct xs_handle *h,
    4.13  		if (val == NULL)
    4.14  			continue;
    4.15  		
    4.16 -		if (strcmp(val, name) == 0) {
    4.17 +		if (strcmp(val, DOMNAME) == 0) {
    4.18  			/* match! */
    4.19  			asprintf(&path, "/local/domain/%s/domid", e[i]);
    4.20  			domid = xs_read(h, xth, path, &len);
     5.1 --- a/tools/blktap/lib/xs_api.h	Thu Oct 05 10:09:25 2006 +0100
     5.2 +++ b/tools/blktap/lib/xs_api.h	Thu Oct 05 10:55:13 2006 +0100
     5.3 @@ -42,7 +42,7 @@ int xs_gather(struct xs_handle *xs, cons
     5.4  int xs_printf(struct xs_handle *h, const char *dir, const char *node, 
     5.5  	      const char *fmt, ...);
     5.6  int xs_exists(struct xs_handle *h, const char *path);
     5.7 -char *get_dom_domid(struct xs_handle *h, const char *name);
     5.8 +char *get_dom_domid(struct xs_handle *h);
     5.9  int convert_dev_name_to_num(char *name);
    5.10  int register_xenbus_watch(struct xs_handle *h, struct xenbus_watch *watch);
    5.11  int unregister_xenbus_watch(struct xs_handle *h, struct xenbus_watch *watch);