ia64/xen-unstable

changeset 6399:6b94eaa59279

Avoid calling device_unregister from device_register callback.
Also simplify code.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Wed Aug 24 20:11:07 2005 +0000 (2005-08-24)
parents 237dc67887cc
children d3c0d85b7ef8
files linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Wed Aug 24 20:10:12 2005 +0000
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Wed Aug 24 20:11:07 2005 +0000
     1.3 @@ -64,7 +64,7 @@ static void frontend_changed(struct xenb
     1.4  		= container_of(watch, struct backend_info, watch);
     1.5  
     1.6  	/* If other end is gone, delete ourself. */
     1.7 -	if (!xenbus_exists(be->frontpath, "")) {
     1.8 +	if (node && !xenbus_exists(be->frontpath, "")) {
     1.9  		xenbus_rm(be->dev->nodename, "");
    1.10  		device_unregister(&be->dev->dev);
    1.11  		return;
    1.12 @@ -139,62 +139,22 @@ static void backend_changed(struct xenbu
    1.13  {
    1.14  	int err;
    1.15  	char *p;
    1.16 -	char *frontend;
    1.17  	long int handle, pdev;
    1.18  	struct backend_info *be
    1.19  		= container_of(watch, struct backend_info, backend_watch);
    1.20  	struct xenbus_device *dev = be->dev;
    1.21  
    1.22 -	frontend = NULL;
    1.23 -	err = xenbus_gather(dev->nodename,
    1.24 -			    "frontend-id", "%li", &be->frontend_id,
    1.25 -			    "frontend", NULL, &frontend,
    1.26 -			    NULL);
    1.27 -	if (XENBUS_EXIST_ERR(err) ||
    1.28 -	    strlen(frontend) == 0 || !xenbus_exists(frontend, "")) {
    1.29 -		/* If we can't get a frontend path and a frontend-id,
    1.30 -		 * then our bus-id is no longer valid and we need to
    1.31 -		 * destroy the backend device.
    1.32 -		 */
    1.33 -		goto device_fail;
    1.34 -	}
    1.35 -	if (err < 0) {
    1.36 -		xenbus_dev_error(dev, err,
    1.37 -				 "reading %s/frontend or frontend-id",
    1.38 -				 dev->nodename);
    1.39 -		goto device_fail;
    1.40 -	}
    1.41 -
    1.42 -	if (!be->frontpath || strcmp(frontend, be->frontpath)) {
    1.43 -		if (be->watch.node)
    1.44 -			unregister_xenbus_watch(&be->watch);
    1.45 -		if (be->frontpath)
    1.46 -			kfree(be->frontpath);
    1.47 -		be->frontpath = frontend;
    1.48 -		frontend = NULL;
    1.49 -		be->watch.node = be->frontpath;
    1.50 -		be->watch.callback = frontend_changed;
    1.51 -		err = register_xenbus_watch(&be->watch);
    1.52 -		if (err) {
    1.53 -			be->watch.node = NULL;
    1.54 -			xenbus_dev_error(dev, err,
    1.55 -					 "adding frontend watch on %s",
    1.56 -					 be->frontpath);
    1.57 -			goto device_fail;
    1.58 -		}
    1.59 -	}
    1.60 -
    1.61  	err = xenbus_scanf(dev->nodename, "physical-device", "%li", &pdev);
    1.62  	if (XENBUS_EXIST_ERR(err))
    1.63 -		goto out;
    1.64 +		return;
    1.65  	if (err < 0) {
    1.66  		xenbus_dev_error(dev, err, "reading physical-device");
    1.67 -		goto device_fail;
    1.68 +		return;
    1.69  	}
    1.70  	if (be->pdev && be->pdev != pdev) {
    1.71  		printk(KERN_WARNING
    1.72  		       "changing physical-device not supported\n");
    1.73 -		goto device_fail;
    1.74 +		return;
    1.75  	}
    1.76  	be->pdev = pdev;
    1.77  
    1.78 @@ -215,32 +175,25 @@ static void backend_changed(struct xenbu
    1.79  			err = PTR_ERR(be->blkif);
    1.80  			be->blkif = NULL;
    1.81  			xenbus_dev_error(dev, err, "creating block interface");
    1.82 -			goto device_fail;
    1.83 +			return;
    1.84  		}
    1.85  
    1.86  		err = vbd_create(be->blkif, handle, be->pdev, be->readonly);
    1.87  		if (err) {
    1.88  			xenbus_dev_error(dev, err, "creating vbd structure");
    1.89 -			goto device_fail;
    1.90 +			return;
    1.91  		}
    1.92  
    1.93 -		frontend_changed(&be->watch, be->frontpath);
    1.94 +		/* Pass in NULL node to skip exist test. */
    1.95 +		frontend_changed(&be->watch, NULL);
    1.96  	}
    1.97 -
    1.98 - out:
    1.99 -	if (frontend)
   1.100 -		kfree(frontend);
   1.101 -	return;
   1.102 -
   1.103 - device_fail:
   1.104 -	device_unregister(&be->dev->dev);
   1.105 -	goto out;
   1.106  }
   1.107  
   1.108  static int blkback_probe(struct xenbus_device *dev,
   1.109  			 const struct xenbus_device_id *id)
   1.110  {
   1.111  	struct backend_info *be;
   1.112 +	char *frontend;
   1.113  	int err;
   1.114  
   1.115  	be = kmalloc(sizeof(*be), GFP_KERNEL);
   1.116 @@ -263,9 +216,46 @@ static int blkback_probe(struct xenbus_d
   1.117  
   1.118  	dev->data = be;
   1.119  
   1.120 +	frontend = NULL;
   1.121 +	err = xenbus_gather(dev->nodename,
   1.122 +			    "frontend-id", "%li", &be->frontend_id,
   1.123 +			    "frontend", NULL, &frontend,
   1.124 +			    NULL);
   1.125 +	if (XENBUS_EXIST_ERR(err))
   1.126 +		goto free_be;
   1.127 +	if (frontend &&
   1.128 +	    (strlen(frontend) == 0 || !xenbus_exists(frontend, ""))) {
   1.129 +		/* If we can't get a frontend path and a frontend-id,
   1.130 +		 * then our bus-id is no longer valid and we need to
   1.131 +		 * destroy the backend device.
   1.132 +		 */
   1.133 +		goto free_be;
   1.134 +	}
   1.135 +	if (err < 0) {
   1.136 +		xenbus_dev_error(dev, err,
   1.137 +				 "reading %s/frontend or frontend-id",
   1.138 +				 dev->nodename);
   1.139 +		goto free_be;
   1.140 +	}
   1.141 +
   1.142 +	be->frontpath = frontend;
   1.143 +	be->watch.node = be->frontpath;
   1.144 +	be->watch.callback = frontend_changed;
   1.145 +	err = register_xenbus_watch(&be->watch);
   1.146 +	if (err) {
   1.147 +		be->watch.node = NULL;
   1.148 +		xenbus_dev_error(dev, err,
   1.149 +				 "adding frontend watch on %s",
   1.150 +				 be->frontpath);
   1.151 +		goto free_be;
   1.152 +	}
   1.153 +
   1.154  	backend_changed(&be->backend_watch, dev->nodename);
   1.155  	return err;
   1.156 +
   1.157   free_be:
   1.158 +	if (frontend)
   1.159 +		kfree(frontend);
   1.160  	kfree(be);
   1.161  	return err;
   1.162  }