xen: Populate xenbus device attributes
authorBastian Blank <waldi@debian.org>
Wed, 29 Jun 2011 12:39:26 +0000 (14:39 +0200)
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Thu, 30 Jun 2011 16:15:29 +0000 (12:15 -0400)
The xenbus bus type uses device_create_file to assign all used device
attributes. However it does not remove them when the device goes away.

This patch uses the dev_attrs field of the bus type to specify default
attributes for all devices.

Signed-off-by: Bastian Blank <waldi@debian.org>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
drivers/xen/xenbus/xenbus_probe.c
drivers/xen/xenbus/xenbus_probe.h
drivers/xen/xenbus/xenbus_probe_backend.c
drivers/xen/xenbus/xenbus_probe_frontend.c

index 739769551e33b98e983b2a76369051b9e2915557..2ed0b045c69a0e66097c06284f7c266db9df69db 100644 (file)
@@ -378,26 +378,31 @@ static void xenbus_dev_release(struct device *dev)
                kfree(to_xenbus_device(dev));
 }
 
-static ssize_t xendev_show_nodename(struct device *dev,
-                                   struct device_attribute *attr, char *buf)
+static ssize_t nodename_show(struct device *dev,
+                            struct device_attribute *attr, char *buf)
 {
        return sprintf(buf, "%s\n", to_xenbus_device(dev)->nodename);
 }
-static DEVICE_ATTR(nodename, S_IRUSR | S_IRGRP | S_IROTH, xendev_show_nodename, NULL);
 
-static ssize_t xendev_show_devtype(struct device *dev,
-                                  struct device_attribute *attr, char *buf)
+static ssize_t devtype_show(struct device *dev,
+                           struct device_attribute *attr, char *buf)
 {
        return sprintf(buf, "%s\n", to_xenbus_device(dev)->devicetype);
 }
-static DEVICE_ATTR(devtype, S_IRUSR | S_IRGRP | S_IROTH, xendev_show_devtype, NULL);
 
-static ssize_t xendev_show_modalias(struct device *dev,
-                                   struct device_attribute *attr, char *buf)
+static ssize_t modalias_show(struct device *dev,
+                            struct device_attribute *attr, char *buf)
 {
        return sprintf(buf, "xen:%s\n", to_xenbus_device(dev)->devicetype);
 }
-static DEVICE_ATTR(modalias, S_IRUSR | S_IRGRP | S_IROTH, xendev_show_modalias, NULL);
+
+struct device_attribute xenbus_dev_attrs[] = {
+       __ATTR_RO(nodename),
+       __ATTR_RO(devtype),
+       __ATTR_RO(modalias),
+       __ATTR_NULL
+};
+EXPORT_SYMBOL_GPL(xenbus_dev_attrs);
 
 int xenbus_probe_node(struct xen_bus_type *bus,
                      const char *type,
@@ -449,25 +454,7 @@ int xenbus_probe_node(struct xen_bus_type *bus,
        if (err)
                goto fail;
 
-       err = device_create_file(&xendev->dev, &dev_attr_nodename);
-       if (err)
-               goto fail_unregister;
-
-       err = device_create_file(&xendev->dev, &dev_attr_devtype);
-       if (err)
-               goto fail_remove_nodename;
-
-       err = device_create_file(&xendev->dev, &dev_attr_modalias);
-       if (err)
-               goto fail_remove_devtype;
-
        return 0;
-fail_remove_devtype:
-       device_remove_file(&xendev->dev, &dev_attr_devtype);
-fail_remove_nodename:
-       device_remove_file(&xendev->dev, &dev_attr_nodename);
-fail_unregister:
-       device_unregister(&xendev->dev);
 fail:
        kfree(xendev);
        return err;
index 888b9900ca082d6772f6e642e4970ab0981a9b0f..b814935378c7a4739fce949f70961505997381b7 100644 (file)
@@ -48,6 +48,8 @@ struct xen_bus_type
        struct bus_type bus;
 };
 
+extern struct device_attribute xenbus_dev_attrs[];
+
 extern int xenbus_match(struct device *_dev, struct device_driver *_drv);
 extern int xenbus_dev_probe(struct device *_dev);
 extern int xenbus_dev_remove(struct device *_dev);
index 6cf467bf63ec8f4c7ed9b720f1c4710d4ee60089..ec510e56282022f7e9f752dc1008b78ced79d79f 100644 (file)
@@ -183,10 +183,6 @@ static void frontend_changed(struct xenbus_watch *watch,
        xenbus_otherend_changed(watch, vec, len, 0);
 }
 
-static struct device_attribute xenbus_backend_dev_attrs[] = {
-       __ATTR_NULL
-};
-
 static struct xen_bus_type xenbus_backend = {
        .root = "backend",
        .levels = 3,            /* backend/type/<frontend>/<id> */
@@ -200,7 +196,7 @@ static struct xen_bus_type xenbus_backend = {
                .probe          = xenbus_dev_probe,
                .remove         = xenbus_dev_remove,
                .shutdown       = xenbus_dev_shutdown,
-               .dev_attrs      = xenbus_backend_dev_attrs,
+               .dev_attrs      = xenbus_dev_attrs,
        },
 };
 
index b6a2690c9d49922676e80bc7eab65b5fffc00a29..ed2ba474a5602158c8d1061207438430f42417c3 100644 (file)
@@ -81,10 +81,6 @@ static void backend_changed(struct xenbus_watch *watch,
        xenbus_otherend_changed(watch, vec, len, 1);
 }
 
-static struct device_attribute xenbus_frontend_dev_attrs[] = {
-       __ATTR_NULL
-};
-
 static const struct dev_pm_ops xenbus_pm_ops = {
        .suspend        = xenbus_dev_suspend,
        .resume         = xenbus_dev_resume,
@@ -106,7 +102,7 @@ static struct xen_bus_type xenbus_frontend = {
                .probe          = xenbus_dev_probe,
                .remove         = xenbus_dev_remove,
                .shutdown       = xenbus_dev_shutdown,
-               .dev_attrs      = xenbus_frontend_dev_attrs,
+               .dev_attrs      = xenbus_dev_attrs,
 
                .pm             = &xenbus_pm_ops,
        },