aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2007-05-21 16:08:01 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2008-01-24 23:40:36 -0500
commitedfaa7c36574f1bf09c65ad602412db9da5f96bf (patch)
treed591b80ff9229e4845e41d68e2f4c5aadb017027 /drivers/base
parent09f82ea92822a7bbb7e816508abbda47ed54a77f (diff)
Driver core: convert block from raw kobjects to core devices
This moves the block devices to /sys/class/block. It will create a flat list of all block devices, with the disks and partitions in one directory. For compatibility /sys/block is created and contains symlinks to the disks. /sys/class/block |-- sda -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda |-- sda1 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1 |-- sda10 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda10 |-- sda5 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5 |-- sda6 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda6 |-- sda7 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda7 |-- sda8 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda8 |-- sda9 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda9 `-- sr0 -> ../../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0 /sys/block/ |-- sda -> ../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda `-- sr0 -> ../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0 Signed-off-by: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/class.c7
-rw-r--r--drivers/base/core.c20
2 files changed, 19 insertions, 8 deletions
diff --git a/drivers/base/class.c b/drivers/base/class.c
index ba6745b0fd2..624b3316e93 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -17,6 +17,7 @@
17#include <linux/kdev_t.h> 17#include <linux/kdev_t.h>
18#include <linux/err.h> 18#include <linux/err.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/genhd.h>
20#include "base.h" 21#include "base.h"
21 22
22#define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr) 23#define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr)
@@ -149,7 +150,13 @@ int class_register(struct class * cls)
149 if (error) 150 if (error)
150 return error; 151 return error;
151 152
153#ifdef CONFIG_SYSFS_DEPRECATED
154 /* let the block class directory show up in the root of sysfs */
155 if (cls != &block_class)
156 cls->subsys.kobj.kset = class_kset;
157#else
152 cls->subsys.kobj.kset = class_kset; 158 cls->subsys.kobj.kset = class_kset;
159#endif
153 cls->subsys.kobj.ktype = &class_ktype; 160 cls->subsys.kobj.ktype = &class_ktype;
154 161
155 error = kset_register(&cls->subsys); 162 error = kset_register(&cls->subsys);
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 13cae18936c..06e8738ab26 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -671,14 +671,15 @@ static int device_add_class_symlinks(struct device *dev)
671 671
672#ifdef CONFIG_SYSFS_DEPRECATED 672#ifdef CONFIG_SYSFS_DEPRECATED
673 /* stacked class devices need a symlink in the class directory */ 673 /* stacked class devices need a symlink in the class directory */
674 if (dev->kobj.parent != &dev->class->subsys.kobj) { 674 if (dev->kobj.parent != &dev->class->subsys.kobj &&
675 dev->type != &part_type) {
675 error = sysfs_create_link(&dev->class->subsys.kobj, &dev->kobj, 676 error = sysfs_create_link(&dev->class->subsys.kobj, &dev->kobj,
676 dev->bus_id); 677 dev->bus_id);
677 if (error) 678 if (error)
678 goto out_subsys; 679 goto out_subsys;
679 } 680 }
680 681
681 if (dev->parent) { 682 if (dev->parent && dev->type != &part_type) {
682 struct device *parent = dev->parent; 683 struct device *parent = dev->parent;
683 char *class_name; 684 char *class_name;
684 685
@@ -707,10 +708,11 @@ static int device_add_class_symlinks(struct device *dev)
707 return 0; 708 return 0;
708 709
709out_device: 710out_device:
710 if (dev->parent) 711 if (dev->parent && dev->type != &part_type)
711 sysfs_remove_link(&dev->kobj, "device"); 712 sysfs_remove_link(&dev->kobj, "device");
712out_busid: 713out_busid:
713 if (dev->kobj.parent != &dev->class->subsys.kobj) 714 if (dev->kobj.parent != &dev->class->subsys.kobj &&
715 dev->type != &part_type)
714 sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id); 716 sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id);
715#else 717#else
716 /* link in the class directory pointing to the device */ 718 /* link in the class directory pointing to the device */
@@ -719,7 +721,7 @@ out_busid:
719 if (error) 721 if (error)
720 goto out_subsys; 722 goto out_subsys;
721 723
722 if (dev->parent) { 724 if (dev->parent && dev->type != &part_type) {
723 error = sysfs_create_link(&dev->kobj, &dev->parent->kobj, 725 error = sysfs_create_link(&dev->kobj, &dev->parent->kobj,
724 "device"); 726 "device");
725 if (error) 727 if (error)
@@ -743,7 +745,7 @@ static void device_remove_class_symlinks(struct device *dev)
743 return; 745 return;
744 746
745#ifdef CONFIG_SYSFS_DEPRECATED 747#ifdef CONFIG_SYSFS_DEPRECATED
746 if (dev->parent) { 748 if (dev->parent && dev->type != &part_type) {
747 char *class_name; 749 char *class_name;
748 750
749 class_name = make_class_name(dev->class->name, &dev->kobj); 751 class_name = make_class_name(dev->class->name, &dev->kobj);
@@ -754,10 +756,11 @@ static void device_remove_class_symlinks(struct device *dev)
754 sysfs_remove_link(&dev->kobj, "device"); 756 sysfs_remove_link(&dev->kobj, "device");
755 } 757 }
756 758
757 if (dev->kobj.parent != &dev->class->subsys.kobj) 759 if (dev->kobj.parent != &dev->class->subsys.kobj &&
760 dev->type != &part_type)
758 sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id); 761 sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id);
759#else 762#else
760 if (dev->parent) 763 if (dev->parent && dev->type != &part_type)
761 sysfs_remove_link(&dev->kobj, "device"); 764 sysfs_remove_link(&dev->kobj, "device");
762 765
763 sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id); 766 sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id);
@@ -925,6 +928,7 @@ struct device * get_device(struct device * dev)
925 */ 928 */
926void put_device(struct device * dev) 929void put_device(struct device * dev)
927{ 930{
931 /* might_sleep(); */
928 if (dev) 932 if (dev)
929 kobject_put(&dev->kobj); 933 kobject_put(&dev->kobj);
930} 934}