ia64/xen-unstable

changeset 11768:ff9746d600e9

[BLKTAP] Formatting and style cleanups to blktapctrl.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Fri Oct 06 15:04:42 2006 +0100 (2006-10-06)
parents 7efaaae37415
children 9ab5db36c987
files tools/blktap/drivers/blktapctrl.c tools/blktap/lib/xenbus.c tools/blktap/lib/xs_api.c
line diff
     1.1 --- a/tools/blktap/drivers/blktapctrl.c	Fri Oct 06 11:52:41 2006 +0100
     1.2 +++ b/tools/blktap/drivers/blktapctrl.c	Fri Oct 06 15:04:42 2006 +0100
     1.3 @@ -684,13 +684,10 @@ int main(int argc, char *argv[])
     1.4  	}
     1.5  	
     1.6  	ret = setup_probe_watch(h);
     1.7 -	if (ret < 0) {
     1.8 +	if (ret != 0) {
     1.9  		DPRINTF("Failed adding device probewatch\n");
    1.10  		xs_daemon_close(h);
    1.11  		goto open_failed;
    1.12 -	} else {
    1.13 -		DPRINTF("Added probe %s\n", 
    1.14 -		       (ret ? "ASYNCHRONOUSLY":"SYNCHRONOUSLY"));
    1.15  	}
    1.16  
    1.17  	ioctl(ctlfd, BLKTAP_IOCTL_SETMODE, BLKTAP_MODE_INTERPOSE );
     2.1 --- a/tools/blktap/lib/xenbus.c	Fri Oct 06 11:52:41 2006 +0100
     2.2 +++ b/tools/blktap/lib/xenbus.c	Fri Oct 06 15:04:42 2006 +0100
     2.3 @@ -166,60 +166,58 @@ static void ueblktap_setup(struct xs_han
     2.4  		goto fail;
     2.5  	}
     2.6  
     2.7 -        deverr = xs_gather(h, bepath, "physical-device", "%li", &pdev, NULL);
     2.8 -        if (!deverr) {
     2.9 -                DPRINTF("pdev set to %ld\n",pdev);
    2.10 -                if (be->pdev && be->pdev != pdev) {
    2.11 -                        DPRINTF("changing physical-device not supported");
    2.12 -                        goto fail;
    2.13 -                }
    2.14 -                be->pdev = pdev;
    2.15 -        }
    2.16 +	deverr = xs_gather(h, bepath, "physical-device", "%li", &pdev, NULL);
    2.17 +	if (!deverr) {
    2.18 +		DPRINTF("pdev set to %ld\n",pdev);
    2.19 +		if (be->pdev && be->pdev != pdev) {
    2.20 +			DPRINTF("changing physical-device not supported");
    2.21 +			goto fail;
    2.22 +		}
    2.23 +		be->pdev = pdev;
    2.24 +	}
    2.25  
    2.26 -        /*Check to see if device is to be opened read-only*/
    2.27 -        asprintf(&path, "%s/%s", bepath, "read-only");
    2.28 -        if (xs_exists(h, path))
    2.29 -                be->readonly = 1;
    2.30 -
    2.31 -        if (be->blkif == NULL) {
    2.32 +	/* Check to see if device is to be opened read-only. */
    2.33 +	asprintf(&path, "%s/%s", bepath, "read-only");
    2.34 +	if (xs_exists(h, path))
    2.35 +		be->readonly = 1;
    2.36  
    2.37 -                /* Front end dir is a number, which is used as the handle. */
    2.38 -                p = strrchr(be->frontpath, '/') + 1;
    2.39 -                handle = strtoul(p, NULL, 0);
    2.40 +	if (be->blkif == NULL) {
    2.41 +		/* Front end dir is a number, which is used as the handle. */
    2.42 +		p = strrchr(be->frontpath, '/') + 1;
    2.43 +		handle = strtoul(p, NULL, 0);
    2.44  
    2.45 -                be->blkif = alloc_blkif(be->frontend_id);
    2.46 -	
    2.47 -                if (be->blkif == NULL)
    2.48 -                        goto fail;
    2.49 +		be->blkif = alloc_blkif(be->frontend_id);
    2.50 +		if (be->blkif == NULL)
    2.51 +			goto fail;
    2.52  
    2.53  		be->blkif->be_id = get_be_id(bepath);
    2.54  		
    2.55 -                /*Insert device specific info*/
    2.56 -                blk = malloc(sizeof(blkif_info_t));
    2.57 +		/* Insert device specific info, */
    2.58 +		blk = malloc(sizeof(blkif_info_t));
    2.59  		if (!blk) {
    2.60  			DPRINTF("Out of memory - blkif_info_t\n");
    2.61  			goto fail;
    2.62  		}
    2.63 -                er = xs_gather(h, bepath, "params", NULL, &blk->params, NULL);
    2.64 -                if (er)
    2.65 -                        goto fail;
    2.66 -                be->blkif->info = blk;
    2.67 +		er = xs_gather(h, bepath, "params", NULL, &blk->params, NULL);
    2.68 +		if (er)
    2.69 +			goto fail;
    2.70 +		be->blkif->info = blk;
    2.71  		
    2.72 -                if (deverr) {
    2.73 -                        /*Dev number was not available, try to set manually*/
    2.74 -                        pdev = convert_dev_name_to_num(blk->params);
    2.75 -                        be->pdev = pdev;
    2.76 -                }
    2.77 +		if (deverr) {
    2.78 +			/*Dev number was not available, try to set manually*/
    2.79 +			pdev = convert_dev_name_to_num(blk->params);
    2.80 +			be->pdev = pdev;
    2.81 +		}
    2.82  
    2.83 -                er = blkif_init(be->blkif, handle, be->pdev, be->readonly);
    2.84 -
    2.85 -                if (er != 0) {
    2.86 -                        DPRINTF("Unable to open device %s\n",blk->params);
    2.87 +		er = blkif_init(be->blkif, handle, be->pdev, be->readonly);
    2.88 +		if (er != 0) {
    2.89 +			DPRINTF("Unable to open device %s\n",blk->params);
    2.90  			goto fail;
    2.91  		}
    2.92  
    2.93 -                DPRINTF("[BECHG]: ADDED A NEW BLKIF (%s)\n", bepath);
    2.94 -        }	
    2.95 +		DPRINTF("[BECHG]: ADDED A NEW BLKIF (%s)\n", bepath);
    2.96 +	}
    2.97 +
    2.98  	/* Supply the information about the device to xenstore */
    2.99  	er = xs_printf(h, be->backpath, "sectors", "%lu",
   2.100  			be->blkif->ops->get_size(be->blkif));
   2.101 @@ -283,10 +281,10 @@ static void ueblktap_probe(struct xs_han
   2.102  	 *asserts that xenstore structure is always 7 levels deep
   2.103  	 *e.g. /local/domain/0/backend/vbd/1/2049
   2.104  	 */
   2.105 -        len = strsep_len(bepath, '/', 7);
   2.106 -        if (len < 0) 
   2.107 -		goto free_be;     
   2.108 -        bepath[len] = '\0';
   2.109 +	len = strsep_len(bepath, '/', 7);
   2.110 +	if (len < 0) 
   2.111 +		goto free_be;
   2.112 +	bepath[len] = '\0';
   2.113  	
   2.114  	be = malloc(sizeof(*be));
   2.115  	if (!be) {
   2.116 @@ -318,22 +316,21 @@ static void ueblktap_probe(struct xs_han
   2.117  		if ( (be != NULL) && (be->blkif != NULL) ) 
   2.118  			backend_remove(h, be);
   2.119  		else goto free_be;
   2.120 -	        if (bepath)
   2.121 +		if (bepath)
   2.122  			free(bepath);
   2.123  		return;
   2.124  	}
   2.125  	
   2.126 -        /* Are we already tracking this device? */
   2.127 -        if (be_exists_be(bepath)) {
   2.128 +	/* Are we already tracking this device? */
   2.129 +	if (be_exists_be(bepath))
   2.130  		goto free_be;
   2.131 -	}
   2.132  	
   2.133  	be->backpath = bepath;
   2.134 -       	be->frontpath = frontend;
   2.135 +	be->frontpath = frontend;
   2.136  	
   2.137 -        list_add(&be->list, &belist);
   2.138 +	list_add(&be->list, &belist);
   2.139  	
   2.140 -        DPRINTF("[PROBE]\tADDED NEW DEVICE (%s)\n", bepath);
   2.141 +	DPRINTF("[PROBE]\tADDED NEW DEVICE (%s)\n", bepath);
   2.142  	DPRINTF("\tFRONTEND (%s),(%ld)\n", frontend,be->frontend_id);
   2.143  	
   2.144  	ueblktap_setup(h, bepath);	
   2.145 @@ -342,11 +339,10 @@ static void ueblktap_probe(struct xs_han
   2.146   free_be:
   2.147  	if (frontend)
   2.148  		free(frontend);
   2.149 -        if (bepath)
   2.150 +	if (bepath)
   2.151  		free(bepath);
   2.152  	if (be) 
   2.153  		free(be);
   2.154 -	return;
   2.155  }
   2.156  
   2.157  /**
   2.158 @@ -360,7 +356,6 @@ int add_blockdevice_probe_watch(struct x
   2.159  {
   2.160  	char *path;
   2.161  	struct xenbus_watch *vbd_watch;
   2.162 -	int er;
   2.163  	
   2.164  	asprintf(&path, "/local/domain/%s/backend/tap", domid);
   2.165  	if (path == NULL) 
   2.166 @@ -373,76 +368,67 @@ int add_blockdevice_probe_watch(struct x
   2.167  	}	
   2.168  	vbd_watch->node     = path;
   2.169  	vbd_watch->callback = ueblktap_probe;
   2.170 -	er = register_xenbus_watch(h, vbd_watch);
   2.171 -	if (er == 0) {
   2.172 +	if (register_xenbus_watch(h, vbd_watch) != 0) {
   2.173  		DPRINTF("ERROR: adding vbd probe watch %s\n", path);
   2.174  		return -EINVAL;
   2.175  	}
   2.176  	return 0;
   2.177  }
   2.178  
   2.179 -/*
   2.180 - *Asynch callback to check for /local/domain/<DOMID>/name
   2.181 - */
   2.182 +/* Asynch callback to check for /local/domain/<DOMID>/name */
   2.183  void check_dom(struct xs_handle *h, struct xenbus_watch *w, 
   2.184 -	       const char *bepath_im) {
   2.185 -	char *domid = NULL;
   2.186 +	       const char *bepath_im)
   2.187 +{
   2.188 +	char *domid;
   2.189  
   2.190  	domid = get_dom_domid(h);
   2.191 -	if (domid) {
   2.192 -		add_blockdevice_probe_watch(h, domid);
   2.193 -		free(domid);
   2.194 -		unregister_xenbus_watch(h, w);
   2.195 -	}
   2.196 -	return;	
   2.197 +	if (domid == NULL)
   2.198 +		return;
   2.199 +
   2.200 +	add_blockdevice_probe_watch(h, domid);
   2.201 +	free(domid);
   2.202 +	unregister_xenbus_watch(h, w);
   2.203  }
   2.204  
   2.205 -/*
   2.206 - *We must wait for xend to register /local/domain/<DOMID>
   2.207 - */
   2.208 +/* We must wait for xend to register /local/domain/<DOMID> */
   2.209  int watch_for_domid(struct xs_handle *h)
   2.210  {
   2.211  	struct xenbus_watch *domid_watch;
   2.212  	char *path = NULL;
   2.213 -	int er;
   2.214  
   2.215  	asprintf(&path, "/local/domain");
   2.216  	if (path == NULL) 
   2.217  		return -ENOMEM;
   2.218  
   2.219 -	domid_watch = (struct xenbus_watch *)malloc(sizeof(struct xenbus_watch));
   2.220 -	if (!domid_watch) {
   2.221 +	domid_watch = malloc(sizeof(struct xenbus_watch));
   2.222 +	if (domid_watch == NULL) {
   2.223  		DPRINTF("ERROR: unable to malloc domid_watch [%s]\n", path);
   2.224  		return -EINVAL;
   2.225  	}	
   2.226 +
   2.227  	domid_watch->node     = path;
   2.228  	domid_watch->callback = check_dom;
   2.229 -	er = register_xenbus_watch(h, domid_watch);
   2.230 -	if (er == 0) {
   2.231 +
   2.232 +	if (register_xenbus_watch(h, domid_watch) != 0) {
   2.233  		DPRINTF("ERROR: adding vbd probe watch %s\n", path);
   2.234  		return -EINVAL;
   2.235  	}
   2.236 -	if (path == NULL) 
   2.237 -		return -ENOMEM;	
   2.238 -	return 1;
   2.239 +
   2.240 +	DPRINTF("Set async watch for /local/domain\n");
   2.241 +
   2.242 +	return 0;
   2.243  }
   2.244  
   2.245  int setup_probe_watch(struct xs_handle *h)
   2.246  {
   2.247 -	char *domid = NULL, *path;
   2.248 +	char *domid;
   2.249  	int ret;
   2.250  	
   2.251  	domid = get_dom_domid(h);
   2.252 +	if (domid == NULL)
   2.253 +		return watch_for_domid(h);
   2.254  
   2.255 -	if (!domid) {
   2.256 -                /*Asynchronous path*/
   2.257 -		ret = watch_for_domid(h);
   2.258 -		goto finish;
   2.259 -	} else {
   2.260 -		/*Synchronous path*/
   2.261 -		ret = add_blockdevice_probe_watch(h, domid);
   2.262 -		free(domid);
   2.263 -	}
   2.264 - finish:
   2.265 +	ret = add_blockdevice_probe_watch(h, domid);
   2.266 +	free(domid);
   2.267  	return ret;
   2.268  }
     3.1 --- a/tools/blktap/lib/xs_api.c	Fri Oct 06 11:52:41 2006 +0100
     3.2 +++ b/tools/blktap/lib/xs_api.c	Fri Oct 06 15:04:42 2006 +0100
     3.3 @@ -106,7 +106,7 @@ again:
     3.4  	if (!xs_transaction_end(xs, xth, ret)) {
     3.5  		if (ret == 0 && errno == EAGAIN)
     3.6  			goto again;
     3.7 -                else
     3.8 +		else
     3.9  			ret = errno;
    3.10  	}
    3.11  
    3.12 @@ -118,25 +118,25 @@ again:
    3.13  int xs_printf(struct xs_handle *h, const char *dir, const char *node, 
    3.14  	      const char *fmt, ...)
    3.15  {
    3.16 -        char *buf, *path;
    3.17 -        va_list ap;
    3.18 -        int ret;
    3.19 +	char *buf, *path;
    3.20 +	va_list ap;
    3.21 +	int ret;
    3.22  	
    3.23 -        va_start(ap, fmt);
    3.24 -        ret = vasprintf(&buf, fmt, ap);
    3.25 -        va_end(ap);
    3.26 +	va_start(ap, fmt);
    3.27 +	ret = vasprintf(&buf, fmt, ap);
    3.28 +	va_end(ap);
    3.29  	
    3.30 -        asprintf(&path, "%s/%s", dir, node);
    3.31 +	asprintf(&path, "%s/%s", dir, node);
    3.32  	
    3.33 -        if ( (path == NULL) || (buf == NULL) )
    3.34 +	if ((path == NULL) || (buf == NULL))
    3.35  		return 0;
    3.36  
    3.37 -        ret = xs_write(h, XBT_NULL, path, buf, strlen(buf)+1);
    3.38 +	ret = xs_write(h, XBT_NULL, path, buf, strlen(buf)+1);
    3.39  	
    3.40 -        free(buf);
    3.41 -        free(path);
    3.42 +	free(buf);
    3.43 +	free(path);
    3.44  	
    3.45 -        return ret;
    3.46 +	return ret;
    3.47  }
    3.48  
    3.49  
    3.50 @@ -179,7 +179,7 @@ char *get_dom_domid(struct xs_handle *h)
    3.51  	}
    3.52  	
    3.53  	e = xs_directory(h, xth, "/local/domain", &num);
    3.54 -	
    3.55 +
    3.56  	for (i = 0; (i < num) && (domid == NULL); i++) {
    3.57  		asprintf(&path, "/local/domain/%s/name", e[i]);
    3.58  		val = xs_read(h, xth, path, &len);
    3.59 @@ -249,12 +249,12 @@ int convert_dev_name_to_num(char *name) 
    3.60  		ret = BASE_DEV_VAL;
    3.61  	}
    3.62  
    3.63 -        free(p_sd);
    3.64 -        free(p_hd);
    3.65 -        free(p_xvd);
    3.66 -        free(p_plx);
    3.67 -        free(alpha);
    3.68 -        
    3.69 +	free(p_sd);
    3.70 +	free(p_hd);
    3.71 +	free(p_xvd);
    3.72 +	free(p_plx);
    3.73 +	free(alpha);
    3.74 +
    3.75  	return ret;
    3.76  }
    3.77  
    3.78 @@ -281,42 +281,39 @@ int register_xenbus_watch(struct xs_hand
    3.79  {
    3.80  	/* Pointer in ascii is the token. */
    3.81  	char token[sizeof(watch) * 2 + 1];
    3.82 -	int er;
    3.83 -	
    3.84 +
    3.85  	sprintf(token, "%lX", (long)watch);
    3.86 -	if (find_watch(token)) 
    3.87 -	{
    3.88 +	if (find_watch(token)) {
    3.89  		DPRINTF("watch collision!\n");
    3.90  		return -EINVAL;
    3.91  	}
    3.92  	
    3.93 -	er = xs_watch(h, watch->node, token);
    3.94 -	if (er != 0) {
    3.95 -		list_add(&watch->list, &watches);
    3.96 -	} 
    3.97 -        
    3.98 -	return er;
    3.99 +	if (!xs_watch(h, watch->node, token)) {
   3.100 +		DPRINTF("unable to set watch!\n");
   3.101 +		return -EINVAL;
   3.102 +	}
   3.103 +
   3.104 +	list_add(&watch->list, &watches);
   3.105 +
   3.106 +	return 0;
   3.107  }
   3.108  
   3.109  int unregister_xenbus_watch(struct xs_handle *h, struct xenbus_watch *watch)
   3.110  {
   3.111  	char token[sizeof(watch) * 2 + 1];
   3.112 -	int er;
   3.113  	
   3.114  	sprintf(token, "%lX", (long)watch);
   3.115 -	if (!find_watch(token))
   3.116 -	{
   3.117 +	if (!find_watch(token)) {
   3.118  		DPRINTF("no such watch!\n");
   3.119  		return -EINVAL;
   3.120  	}
   3.121 -	
   3.122 -	
   3.123 -	er = xs_unwatch(h, watch->node, token);
   3.124 +
   3.125 +	if (!xs_unwatch(h, watch->node, token))
   3.126 +		DPRINTF("XENBUS Failed to release watch %s: %i\n",
   3.127 +			watch->node, er);
   3.128 +
   3.129  	list_del(&watch->list);
   3.130  	
   3.131 -	if (er == 0)
   3.132 -		DPRINTF("XENBUS Failed to release watch %s: %i\n",
   3.133 -		     watch->node, er);
   3.134  	return 0;
   3.135  }
   3.136  
   3.137 @@ -354,14 +351,10 @@ int xs_fire_next_watch(struct xs_handle 
   3.138  	token = res[XS_WATCH_TOKEN];
   3.139  	
   3.140  	w = find_watch(token);
   3.141 -	if (!w)
   3.142 -	{
   3.143 -		DPRINTF("unregistered watch fired\n");
   3.144 -		goto done;
   3.145 -	}
   3.146 -	w->callback(h, w, node);
   3.147 -	
   3.148 - done:
   3.149 +	if (w)
   3.150 +		w->callback(h, w, node);
   3.151 +
   3.152  	free(res);
   3.153 +
   3.154  	return 1;
   3.155  }