WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] Avoid calling device_unregister from device_register cal

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] Avoid calling device_unregister from device_register callback.
From: Xen patchbot -unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 24 Aug 2005 20:12:13 +0000
Delivery-date: Wed, 24 Aug 2005 20:10:38 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User cl349@xxxxxxxxxxxxxxxxxxxx
# Node ID 6b94eaa59279b2a3a5917779f42b58abcd3478c3
# Parent  237dc67887cc6716359545a46edbbe1c17353722
Avoid calling device_unregister from device_register callback.
Also simplify code.
Signed-off-by: Christian Limpach <Christian.Limpach@xxxxxxxxxxxx>

diff -r 237dc67887cc -r 6b94eaa59279 
linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c
--- a/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c Wed Aug 24 20:10:12 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c Wed Aug 24 20:11:07 2005
@@ -64,7 +64,7 @@
                = container_of(watch, struct backend_info, watch);
 
        /* If other end is gone, delete ourself. */
-       if (!xenbus_exists(be->frontpath, "")) {
+       if (node && !xenbus_exists(be->frontpath, "")) {
                xenbus_rm(be->dev->nodename, "");
                device_unregister(&be->dev->dev);
                return;
@@ -139,133 +139,123 @@
 {
        int err;
        char *p;
-       char *frontend;
        long int handle, pdev;
        struct backend_info *be
                = container_of(watch, struct backend_info, backend_watch);
        struct xenbus_device *dev = be->dev;
+
+       err = xenbus_scanf(dev->nodename, "physical-device", "%li", &pdev);
+       if (XENBUS_EXIST_ERR(err))
+               return;
+       if (err < 0) {
+               xenbus_dev_error(dev, err, "reading physical-device");
+               return;
+       }
+       if (be->pdev && be->pdev != pdev) {
+               printk(KERN_WARNING
+                      "changing physical-device not supported\n");
+               return;
+       }
+       be->pdev = pdev;
+
+       /* If there's a read-only node, we're read only. */
+       p = xenbus_read(dev->nodename, "read-only", NULL);
+       if (!IS_ERR(p)) {
+               be->readonly = 1;
+               kfree(p);
+       }
+
+       if (be->blkif == NULL) {
+               /* Front end dir is a number, which is used as the handle. */
+               p = strrchr(be->frontpath, '/') + 1;
+               handle = simple_strtoul(p, NULL, 0);
+
+               be->blkif = alloc_blkif(be->frontend_id);
+               if (IS_ERR(be->blkif)) {
+                       err = PTR_ERR(be->blkif);
+                       be->blkif = NULL;
+                       xenbus_dev_error(dev, err, "creating block interface");
+                       return;
+               }
+
+               err = vbd_create(be->blkif, handle, be->pdev, be->readonly);
+               if (err) {
+                       xenbus_dev_error(dev, err, "creating vbd structure");
+                       return;
+               }
+
+               /* Pass in NULL node to skip exist test. */
+               frontend_changed(&be->watch, NULL);
+       }
+}
+
+static int blkback_probe(struct xenbus_device *dev,
+                        const struct xenbus_device_id *id)
+{
+       struct backend_info *be;
+       char *frontend;
+       int err;
+
+       be = kmalloc(sizeof(*be), GFP_KERNEL);
+       if (!be) {
+               xenbus_dev_error(dev, -ENOMEM, "allocating backend structure");
+               return -ENOMEM;
+       }
+
+       memset(be, 0, sizeof(*be));
+
+       be->dev = dev;
+       be->backend_watch.node = dev->nodename;
+       be->backend_watch.callback = backend_changed;
+       err = register_xenbus_watch(&be->backend_watch);
+       if (err) {
+               xenbus_dev_error(dev, err, "adding backend watch on %s",
+                                dev->nodename);
+               goto free_be;
+       }
+
+       dev->data = be;
 
        frontend = NULL;
        err = xenbus_gather(dev->nodename,
                            "frontend-id", "%li", &be->frontend_id,
                            "frontend", NULL, &frontend,
                            NULL);
-       if (XENBUS_EXIST_ERR(err) ||
-           strlen(frontend) == 0 || !xenbus_exists(frontend, "")) {
+       if (XENBUS_EXIST_ERR(err))
+               goto free_be;
+       if (frontend &&
+           (strlen(frontend) == 0 || !xenbus_exists(frontend, ""))) {
                /* If we can't get a frontend path and a frontend-id,
                 * then our bus-id is no longer valid and we need to
                 * destroy the backend device.
                 */
-               goto device_fail;
+               goto free_be;
        }
        if (err < 0) {
                xenbus_dev_error(dev, err,
                                 "reading %s/frontend or frontend-id",
                                 dev->nodename);
-               goto device_fail;
-       }
-
-       if (!be->frontpath || strcmp(frontend, be->frontpath)) {
-               if (be->watch.node)
-                       unregister_xenbus_watch(&be->watch);
-               if (be->frontpath)
-                       kfree(be->frontpath);
-               be->frontpath = frontend;
-               frontend = NULL;
-               be->watch.node = be->frontpath;
-               be->watch.callback = frontend_changed;
-               err = register_xenbus_watch(&be->watch);
-               if (err) {
-                       be->watch.node = NULL;
-                       xenbus_dev_error(dev, err,
-                                        "adding frontend watch on %s",
-                                        be->frontpath);
-                       goto device_fail;
-               }
-       }
-
-       err = xenbus_scanf(dev->nodename, "physical-device", "%li", &pdev);
-       if (XENBUS_EXIST_ERR(err))
-               goto out;
-       if (err < 0) {
-               xenbus_dev_error(dev, err, "reading physical-device");
-               goto device_fail;
-       }
-       if (be->pdev && be->pdev != pdev) {
-               printk(KERN_WARNING
-                      "changing physical-device not supported\n");
-               goto device_fail;
-       }
-       be->pdev = pdev;
-
-       /* If there's a read-only node, we're read only. */
-       p = xenbus_read(dev->nodename, "read-only", NULL);
-       if (!IS_ERR(p)) {
-               be->readonly = 1;
-               kfree(p);
-       }
-
-       if (be->blkif == NULL) {
-               /* Front end dir is a number, which is used as the handle. */
-               p = strrchr(be->frontpath, '/') + 1;
-               handle = simple_strtoul(p, NULL, 0);
-
-               be->blkif = alloc_blkif(be->frontend_id);
-               if (IS_ERR(be->blkif)) {
-                       err = PTR_ERR(be->blkif);
-                       be->blkif = NULL;
-                       xenbus_dev_error(dev, err, "creating block interface");
-                       goto device_fail;
-               }
-
-               err = vbd_create(be->blkif, handle, be->pdev, be->readonly);
-               if (err) {
-                       xenbus_dev_error(dev, err, "creating vbd structure");
-                       goto device_fail;
-               }
-
-               frontend_changed(&be->watch, be->frontpath);
-       }
-
- out:
+               goto free_be;
+       }
+
+       be->frontpath = frontend;
+       be->watch.node = be->frontpath;
+       be->watch.callback = frontend_changed;
+       err = register_xenbus_watch(&be->watch);
+       if (err) {
+               be->watch.node = NULL;
+               xenbus_dev_error(dev, err,
+                                "adding frontend watch on %s",
+                                be->frontpath);
+               goto free_be;
+       }
+
+       backend_changed(&be->backend_watch, dev->nodename);
+       return err;
+
+ free_be:
        if (frontend)
                kfree(frontend);
-       return;
-
- device_fail:
-       device_unregister(&be->dev->dev);
-       goto out;
-}
-
-static int blkback_probe(struct xenbus_device *dev,
-                        const struct xenbus_device_id *id)
-{
-       struct backend_info *be;
-       int err;
-
-       be = kmalloc(sizeof(*be), GFP_KERNEL);
-       if (!be) {
-               xenbus_dev_error(dev, -ENOMEM, "allocating backend structure");
-               return -ENOMEM;
-       }
-
-       memset(be, 0, sizeof(*be));
-
-       be->dev = dev;
-       be->backend_watch.node = dev->nodename;
-       be->backend_watch.callback = backend_changed;
-       err = register_xenbus_watch(&be->backend_watch);
-       if (err) {
-               xenbus_dev_error(dev, err, "adding backend watch on %s",
-                                dev->nodename);
-               goto free_be;
-       }
-
-       dev->data = be;
-
-       backend_changed(&be->backend_watch, dev->nodename);
-       return err;
- free_be:
        kfree(be);
        return err;
 }

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] Avoid calling device_unregister from device_register callback., Xen patchbot -unstable <=