ia64/xen-unstable

changeset 6278:73b23942d6f5

Fix driver to work with updated probe driver.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Fri Aug 19 12:14:41 2005 +0000 (2005-08-19)
parents b399599f2ff8
children a86fb4df3bdd
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	Fri Aug 19 12:13:31 2005 +0000
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Fri Aug 19 12:14:41 2005 +0000
     1.3 @@ -44,11 +44,15 @@ static int blkback_remove(struct xenbus_
     1.4  {
     1.5  	struct backend_info *be = dev->data;
     1.6  
     1.7 -	unregister_xenbus_watch(&be->watch);
     1.8 +	if (be->watch.node)
     1.9 +		unregister_xenbus_watch(&be->watch);
    1.10  	unregister_xenbus_watch(&be->backend_watch);
    1.11 -	vbd_free(be->blkif, be->vbd);
    1.12 -	blkif_put(be->blkif);
    1.13 -	kfree(be->frontpath);
    1.14 +	if (be->vbd)
    1.15 +		vbd_free(be->blkif, be->vbd);
    1.16 +	if (be->blkif)
    1.17 +		blkif_put(be->blkif);
    1.18 +	if (be->frontpath)
    1.19 +		kfree(be->frontpath);
    1.20  	kfree(be);
    1.21  	return 0;
    1.22  }
    1.23 @@ -62,17 +66,14 @@ static void frontend_changed(struct xenb
    1.24  	struct backend_info *be
    1.25  		= container_of(watch, struct backend_info, watch);
    1.26  
    1.27 -	// printk("Got front end event on %s (%s)\n", node, be->frontpath);
    1.28 -
    1.29 -	if (vbd_is_active(be->vbd)) {
    1.30 -		/* If other end is gone, delete ourself. */
    1.31 -		if (!xenbus_exists(be->frontpath, "")) {
    1.32 -			// printk("Removing...\n");
    1.33 -			xenbus_rm(be->dev->nodename, "");
    1.34 -			device_unregister(&be->dev->dev);
    1.35 -		}
    1.36 +	/* If other end is gone, delete ourself. */
    1.37 +	if (!xenbus_exists(be->frontpath, "")) {
    1.38 +		xenbus_rm(be->dev->nodename, "");
    1.39 +		device_unregister(&be->dev->dev);
    1.40  		return;
    1.41  	}
    1.42 +	if (vbd_is_active(be->vbd))
    1.43 +		return;
    1.44  
    1.45  #ifndef CONFIG_XEN_BLKDEV_GRANT
    1.46  	err = xenbus_gather(be->frontpath, "shared-frame", "%lu", &sharedmfn,
    1.47 @@ -176,42 +177,20 @@ static void backend_changed(struct xenbu
    1.48  		= container_of(watch, struct backend_info, backend_watch);
    1.49  	struct xenbus_device *dev = be->dev;
    1.50  
    1.51 -	err = xenbus_scanf(dev->nodename, "frontend-id", "%li",
    1.52 -			   &be->frontend_id);
    1.53 -	if (err == -ENOENT || err == -ERANGE)
    1.54 -		goto out;
    1.55 -	if (err < 0) {
    1.56 -		xenbus_dev_error(dev, err, "Reading frontend-id");
    1.57 -		goto out;
    1.58 -	}
    1.59 -
    1.60 -	err = xenbus_scanf(dev->nodename, "physical-device", "%li", &pdev);
    1.61 -	if (err == -ENOENT || err == -ERANGE)
    1.62 -		goto out;
    1.63 -	if (err < 0) {
    1.64 -		xenbus_dev_error(dev, err, "Reading physical-device");
    1.65 -		goto out;
    1.66 -	}
    1.67 -	if (be->pdev && be->pdev != pdev) {
    1.68 -		printk(KERN_WARNING
    1.69 -		       "changing physical-device not supported\n");
    1.70 -		return;
    1.71 -	}
    1.72 -	be->pdev = pdev;
    1.73 -
    1.74 -	frontend = xenbus_read(dev->nodename, "frontend", NULL);
    1.75 -	if (IS_ERR(frontend))
    1.76 -		return;
    1.77 -	if (strlen(frontend) == 0) {
    1.78 -		kfree(frontend);
    1.79 -		return;
    1.80 -	}
    1.81 -
    1.82 -	/* If there's a read-only node, we're read only. */
    1.83 -	p = xenbus_read(dev->nodename, "read-only", NULL);
    1.84 -	if (!IS_ERR(p)) {
    1.85 -		be->readonly = 1;
    1.86 -		kfree(p);
    1.87 +	frontend = NULL;
    1.88 +	err = xenbus_gather(dev->nodename,
    1.89 +			    "frontend-id", "%li", &be->frontend_id,
    1.90 +			    "frontend", NULL, &frontend,
    1.91 +			    NULL);
    1.92 +	if (err == -ENOENT || err == -ERANGE ||
    1.93 +	    strlen(frontend) == 0 || !xenbus_exists(frontend, "")) {
    1.94 +		if (frontend)
    1.95 +			kfree(frontend);
    1.96 +		/* If we can't get a frontend path and a frontend-id,
    1.97 +		 * then our bus-id is no longer valid and we need to
    1.98 +		 * destroy the backend device.
    1.99 +		 */
   1.100 +		goto device_fail;
   1.101  	}
   1.102  
   1.103  	if (!be->frontpath || strcmp(frontend, be->frontpath)) {
   1.104 @@ -223,9 +202,35 @@ static void backend_changed(struct xenbu
   1.105  		be->watch.node = be->frontpath;
   1.106  		be->watch.callback = frontend_changed;
   1.107  		err = register_xenbus_watch(&be->watch);
   1.108 -		if (err)
   1.109 -			goto out;
   1.110 +		if (err) {
   1.111 +			be->watch.node = NULL;
   1.112 +			goto device_fail;
   1.113 +		}
   1.114 +	} else
   1.115 +		kfree(frontend);
   1.116  
   1.117 +	err = xenbus_scanf(dev->nodename, "physical-device", "%li", &pdev);
   1.118 +	if (err == -ENOENT || err == -ERANGE)
   1.119 +		goto out;
   1.120 +	if (err < 0) {
   1.121 +		xenbus_dev_error(dev, err, "Reading physical-device");
   1.122 +		goto device_fail;
   1.123 +	}
   1.124 +	if (be->pdev && be->pdev != pdev) {
   1.125 +		printk(KERN_WARNING
   1.126 +		       "changing physical-device not supported\n");
   1.127 +		goto device_fail;
   1.128 +	}
   1.129 +	be->pdev = pdev;
   1.130 +
   1.131 +	/* If there's a read-only node, we're read only. */
   1.132 +	p = xenbus_read(dev->nodename, "read-only", NULL);
   1.133 +	if (!IS_ERR(p)) {
   1.134 +		be->readonly = 1;
   1.135 +		kfree(p);
   1.136 +	}
   1.137 +
   1.138 +	if (be->blkif == NULL) {
   1.139  		/* Front end dir is a number, which is used as the handle. */
   1.140  		p = strrchr(be->frontpath, '/') + 1;
   1.141  		handle = simple_strtoul(p, NULL, 0);
   1.142 @@ -234,30 +239,24 @@ static void backend_changed(struct xenbu
   1.143  		if (IS_ERR(be->blkif)) {
   1.144  			err = PTR_ERR(be->blkif);
   1.145  			be->blkif = NULL;
   1.146 -			goto free_watch;
   1.147 +			goto device_fail;
   1.148  		}
   1.149  
   1.150  		be->vbd = vbd_create(be->blkif, handle, be->pdev,
   1.151  				     be->readonly);
   1.152  		if (IS_ERR(be->vbd)) {
   1.153  			err = PTR_ERR(be->vbd);
   1.154 -			blkif_put(be->blkif);
   1.155 -			be->blkif = NULL;
   1.156  			be->vbd = NULL;
   1.157 -			goto free_watch;
   1.158 +			goto device_fail;
   1.159  		}
   1.160  
   1.161  		frontend_changed(&be->watch, be->frontpath);
   1.162 -	} else
   1.163 -		kfree(frontend);
   1.164 +	}
   1.165  
   1.166  	return;
   1.167  
   1.168 - free_watch:
   1.169 -	unregister_xenbus_watch(&be->watch);
   1.170 -	be->watch.node = NULL;
   1.171 -	kfree(be->frontpath);
   1.172 -	be->frontpath = NULL;
   1.173 + device_fail:
   1.174 +	device_unregister(&be->dev->dev);
   1.175   out:
   1.176  	return;
   1.177  }
   1.178 @@ -296,7 +295,7 @@ static struct xenbus_device_id blkback_i
   1.179  };
   1.180  
   1.181  static struct xenbus_driver blkback = {
   1.182 -	.name = __stringify(KBUILD_MODNAME),
   1.183 +	.name = "vbd",
   1.184  	.owner = THIS_MODULE,
   1.185  	.ids = blkback_ids,
   1.186  	.probe = blkback_probe,