aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
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
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')
-rw-r--r--drivers/base/class.c7
-rw-r--r--drivers/base/core.c20
-rw-r--r--drivers/block/aoe/aoeblk.c51
-rw-r--r--drivers/block/nbd.c15
-rw-r--r--drivers/ide/ide-probe.c2
-rw-r--r--drivers/md/dm.c4
-rw-r--r--drivers/md/md.c8
7 files changed, 60 insertions, 47 deletions
diff --git a/drivers/base/class.c b/drivers/base/class.c
index ba6745b0fd2f..624b3316e938 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 13cae18936c5..06e8738ab263 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}
diff --git a/drivers/block/aoe/aoeblk.c b/drivers/block/aoe/aoeblk.c
index ad00b3d94711..826d12381e21 100644
--- a/drivers/block/aoe/aoeblk.c
+++ b/drivers/block/aoe/aoeblk.c
@@ -15,8 +15,10 @@
15 15
16static struct kmem_cache *buf_pool_cache; 16static struct kmem_cache *buf_pool_cache;
17 17
18static ssize_t aoedisk_show_state(struct gendisk * disk, char *page) 18static ssize_t aoedisk_show_state(struct device *dev,
19 struct device_attribute *attr, char *page)
19{ 20{
21 struct gendisk *disk = dev_to_disk(dev);
20 struct aoedev *d = disk->private_data; 22 struct aoedev *d = disk->private_data;
21 23
22 return snprintf(page, PAGE_SIZE, 24 return snprintf(page, PAGE_SIZE,
@@ -26,50 +28,47 @@ static ssize_t aoedisk_show_state(struct gendisk * disk, char *page)
26 (d->nopen && !(d->flags & DEVFL_UP)) ? ",closewait" : ""); 28 (d->nopen && !(d->flags & DEVFL_UP)) ? ",closewait" : "");
27 /* I'd rather see nopen exported so we can ditch closewait */ 29 /* I'd rather see nopen exported so we can ditch closewait */
28} 30}
29static ssize_t aoedisk_show_mac(struct gendisk * disk, char *page) 31static ssize_t aoedisk_show_mac(struct device *dev,
32 struct device_attribute *attr, char *page)
30{ 33{
34 struct gendisk *disk = dev_to_disk(dev);
31 struct aoedev *d = disk->private_data; 35 struct aoedev *d = disk->private_data;
32 36
33 return snprintf(page, PAGE_SIZE, "%012llx\n", 37 return snprintf(page, PAGE_SIZE, "%012llx\n",
34 (unsigned long long)mac_addr(d->addr)); 38 (unsigned long long)mac_addr(d->addr));
35} 39}
36static ssize_t aoedisk_show_netif(struct gendisk * disk, char *page) 40static ssize_t aoedisk_show_netif(struct device *dev,
41 struct device_attribute *attr, char *page)
37{ 42{
43 struct gendisk *disk = dev_to_disk(dev);
38 struct aoedev *d = disk->private_data; 44 struct aoedev *d = disk->private_data;
39 45
40 return snprintf(page, PAGE_SIZE, "%s\n", d->ifp->name); 46 return snprintf(page, PAGE_SIZE, "%s\n", d->ifp->name);
41} 47}
42/* firmware version */ 48/* firmware version */
43static ssize_t aoedisk_show_fwver(struct gendisk * disk, char *page) 49static ssize_t aoedisk_show_fwver(struct device *dev,
50 struct device_attribute *attr, char *page)
44{ 51{
52 struct gendisk *disk = dev_to_disk(dev);
45 struct aoedev *d = disk->private_data; 53 struct aoedev *d = disk->private_data;
46 54
47 return snprintf(page, PAGE_SIZE, "0x%04x\n", (unsigned int) d->fw_ver); 55 return snprintf(page, PAGE_SIZE, "0x%04x\n", (unsigned int) d->fw_ver);
48} 56}
49 57
50static struct disk_attribute disk_attr_state = { 58static DEVICE_ATTR(state, S_IRUGO, aoedisk_show_state, NULL);
51 .attr = {.name = "state", .mode = S_IRUGO }, 59static DEVICE_ATTR(mac, S_IRUGO, aoedisk_show_mac, NULL);
52 .show = aoedisk_show_state 60static DEVICE_ATTR(netif, S_IRUGO, aoedisk_show_netif, NULL);
53}; 61static struct device_attribute dev_attr_firmware_version = {
54static struct disk_attribute disk_attr_mac = { 62 .attr = { .name = "firmware-version", .mode = S_IRUGO, .owner = THIS_MODULE },
55 .attr = {.name = "mac", .mode = S_IRUGO }, 63 .show = aoedisk_show_fwver,
56 .show = aoedisk_show_mac
57};
58static struct disk_attribute disk_attr_netif = {
59 .attr = {.name = "netif", .mode = S_IRUGO },
60 .show = aoedisk_show_netif
61};
62static struct disk_attribute disk_attr_fwver = {
63 .attr = {.name = "firmware-version", .mode = S_IRUGO },
64 .show = aoedisk_show_fwver
65}; 64};
66 65
67static struct attribute *aoe_attrs[] = { 66static struct attribute *aoe_attrs[] = {
68 &disk_attr_state.attr, 67 &dev_attr_state.attr,
69 &disk_attr_mac.attr, 68 &dev_attr_mac.attr,
70 &disk_attr_netif.attr, 69 &dev_attr_netif.attr,
71 &disk_attr_fwver.attr, 70 &dev_attr_firmware_version.attr,
72 NULL 71 NULL,
73}; 72};
74 73
75static const struct attribute_group attr_group = { 74static const struct attribute_group attr_group = {
@@ -79,12 +78,12 @@ static const struct attribute_group attr_group = {
79static int 78static int
80aoedisk_add_sysfs(struct aoedev *d) 79aoedisk_add_sysfs(struct aoedev *d)
81{ 80{
82 return sysfs_create_group(&d->gd->kobj, &attr_group); 81 return sysfs_create_group(&d->gd->dev.kobj, &attr_group);
83} 82}
84void 83void
85aoedisk_rm_sysfs(struct aoedev *d) 84aoedisk_rm_sysfs(struct aoedev *d)
86{ 85{
87 sysfs_remove_group(&d->gd->kobj, &attr_group); 86 sysfs_remove_group(&d->gd->dev.kobj, &attr_group);
88} 87}
89 88
90static int 89static int
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index b4c0888aedc3..ba9b17e507e0 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -375,14 +375,17 @@ harderror:
375 return NULL; 375 return NULL;
376} 376}
377 377
378static ssize_t pid_show(struct gendisk *disk, char *page) 378static ssize_t pid_show(struct device *dev,
379 struct device_attribute *attr, char *buf)
379{ 380{
380 return sprintf(page, "%ld\n", 381 struct gendisk *disk = dev_to_disk(dev);
382
383 return sprintf(buf, "%ld\n",
381 (long) ((struct nbd_device *)disk->private_data)->pid); 384 (long) ((struct nbd_device *)disk->private_data)->pid);
382} 385}
383 386
384static struct disk_attribute pid_attr = { 387static struct device_attribute pid_attr = {
385 .attr = { .name = "pid", .mode = S_IRUGO }, 388 .attr = { .name = "pid", .mode = S_IRUGO, .owner = THIS_MODULE },
386 .show = pid_show, 389 .show = pid_show,
387}; 390};
388 391
@@ -394,7 +397,7 @@ static int nbd_do_it(struct nbd_device *lo)
394 BUG_ON(lo->magic != LO_MAGIC); 397 BUG_ON(lo->magic != LO_MAGIC);
395 398
396 lo->pid = current->pid; 399 lo->pid = current->pid;
397 ret = sysfs_create_file(&lo->disk->kobj, &pid_attr.attr); 400 ret = sysfs_create_file(&lo->disk->dev.kobj, &pid_attr.attr);
398 if (ret) { 401 if (ret) {
399 printk(KERN_ERR "nbd: sysfs_create_file failed!"); 402 printk(KERN_ERR "nbd: sysfs_create_file failed!");
400 return ret; 403 return ret;
@@ -403,7 +406,7 @@ static int nbd_do_it(struct nbd_device *lo)
403 while ((req = nbd_read_stat(lo)) != NULL) 406 while ((req = nbd_read_stat(lo)) != NULL)
404 nbd_end_request(req); 407 nbd_end_request(req);
405 408
406 sysfs_remove_file(&lo->disk->kobj, &pid_attr.attr); 409 sysfs_remove_file(&lo->disk->dev.kobj, &pid_attr.attr);
407 return 0; 410 return 0;
408} 411}
409 412
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 2994523be7bf..0cb3d2bb3ab9 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -1173,7 +1173,7 @@ static struct kobject *exact_match(dev_t dev, int *part, void *data)
1173{ 1173{
1174 struct gendisk *p = data; 1174 struct gendisk *p = data;
1175 *part &= (1 << PARTN_BITS) - 1; 1175 *part &= (1 << PARTN_BITS) - 1;
1176 return &p->kobj; 1176 return &p->dev.kobj;
1177} 1177}
1178 1178
1179static int exact_lock(dev_t dev, void *data) 1179static int exact_lock(dev_t dev, void *data)
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 88c0fd657825..f2d24eb3208c 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -1109,7 +1109,7 @@ static void event_callback(void *context)
1109 list_splice_init(&md->uevent_list, &uevents); 1109 list_splice_init(&md->uevent_list, &uevents);
1110 spin_unlock_irqrestore(&md->uevent_lock, flags); 1110 spin_unlock_irqrestore(&md->uevent_lock, flags);
1111 1111
1112 dm_send_uevents(&uevents, &md->disk->kobj); 1112 dm_send_uevents(&uevents, &md->disk->dev.kobj);
1113 1113
1114 atomic_inc(&md->event_nr); 1114 atomic_inc(&md->event_nr);
1115 wake_up(&md->eventq); 1115 wake_up(&md->eventq);
@@ -1530,7 +1530,7 @@ out:
1530 *---------------------------------------------------------------*/ 1530 *---------------------------------------------------------------*/
1531void dm_kobject_uevent(struct mapped_device *md) 1531void dm_kobject_uevent(struct mapped_device *md)
1532{ 1532{
1533 kobject_uevent(&md->disk->kobj, KOBJ_CHANGE); 1533 kobject_uevent(&md->disk->dev.kobj, KOBJ_CHANGE);
1534} 1534}
1535 1535
1536uint32_t dm_next_uevent_seq(struct mapped_device *md) 1536uint32_t dm_next_uevent_seq(struct mapped_device *md)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index c5030863d004..f79efb359215 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1396,9 +1396,9 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
1396 goto fail; 1396 goto fail;
1397 1397
1398 if (rdev->bdev->bd_part) 1398 if (rdev->bdev->bd_part)
1399 ko = &rdev->bdev->bd_part->kobj; 1399 ko = &rdev->bdev->bd_part->dev.kobj;
1400 else 1400 else
1401 ko = &rdev->bdev->bd_disk->kobj; 1401 ko = &rdev->bdev->bd_disk->dev.kobj;
1402 if ((err = sysfs_create_link(&rdev->kobj, ko, "block"))) { 1402 if ((err = sysfs_create_link(&rdev->kobj, ko, "block"))) {
1403 kobject_del(&rdev->kobj); 1403 kobject_del(&rdev->kobj);
1404 goto fail; 1404 goto fail;
@@ -3083,7 +3083,7 @@ static struct kobject *md_probe(dev_t dev, int *part, void *data)
3083 add_disk(disk); 3083 add_disk(disk);
3084 mddev->gendisk = disk; 3084 mddev->gendisk = disk;
3085 mutex_unlock(&disks_mutex); 3085 mutex_unlock(&disks_mutex);
3086 error = kobject_init_and_add(&mddev->kobj, &md_ktype, &disk->kobj, 3086 error = kobject_init_and_add(&mddev->kobj, &md_ktype, &disk->dev.kobj,
3087 "%s", "md"); 3087 "%s", "md");
3088 if (error) 3088 if (error)
3089 printk(KERN_WARNING "md: cannot register %s/md - name in use\n", 3089 printk(KERN_WARNING "md: cannot register %s/md - name in use\n",
@@ -3361,7 +3361,7 @@ static int do_md_run(mddev_t * mddev)
3361 3361
3362 mddev->changed = 1; 3362 mddev->changed = 1;
3363 md_new_event(mddev); 3363 md_new_event(mddev);
3364 kobject_uevent(&mddev->gendisk->kobj, KOBJ_CHANGE); 3364 kobject_uevent(&mddev->gendisk->dev.kobj, KOBJ_CHANGE);
3365 return 0; 3365 return 0;
3366} 3366}
3367 3367