aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@suse.de>2006-06-15 09:31:56 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2006-06-21 15:40:49 -0400
commitb9d9c82b4d081feb464f62dfc786c8621d09ecd2 (patch)
tree511d15b4d7aaba80a2c0fe49622a3224ca386122
parent23681e479129854305da1da32f7f1eaf635ef22c (diff)
[PATCH] Driver core: add generic "subsystem" link to all devices
Like the SUBSYTEM= key we find in the environment of the uevent, this creates a generic "subsystem" link in sysfs for every device. Userspace usually doesn't care at all if its a "class" or a "bus" device. This provides an unified way to determine the subsytem of a device, regardless of the way the driver core has created it. Signed-off-by: Kay Sievers <kay.sievers@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--block/genhd.c7
-rw-r--r--drivers/base/bus.c2
-rw-r--r--drivers/base/class.c2
-rw-r--r--drivers/base/core.c9
-rw-r--r--fs/partitions/check.c4
5 files changed, 17 insertions, 7 deletions
diff --git a/block/genhd.c b/block/genhd.c
index 5a8d3bf02f17..8d7339511e5e 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -17,8 +17,7 @@
17#include <linux/buffer_head.h> 17#include <linux/buffer_head.h>
18#include <linux/mutex.h> 18#include <linux/mutex.h>
19 19
20static struct subsystem block_subsys; 20struct subsystem block_subsys;
21
22static DEFINE_MUTEX(block_subsys_lock); 21static DEFINE_MUTEX(block_subsys_lock);
23 22
24/* 23/*
@@ -511,9 +510,7 @@ static struct kset_uevent_ops block_uevent_ops = {
511 .uevent = block_uevent, 510 .uevent = block_uevent,
512}; 511};
513 512
514/* declare block_subsys. */ 513decl_subsys(block, &ktype_block, &block_uevent_ops);
515static decl_subsys(block, &ktype_block, &block_uevent_ops);
516
517 514
518/* 515/*
519 * aggregate disk stat collector. Uses the same stats that the sysfs 516 * aggregate disk stat collector. Uses the same stats that the sysfs
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 64ba9011d1a8..050d86d0b872 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -374,6 +374,7 @@ int bus_add_device(struct device * dev)
374 error = device_add_attrs(bus, dev); 374 error = device_add_attrs(bus, dev);
375 if (!error) { 375 if (!error) {
376 sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id); 376 sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id);
377 sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "subsystem");
377 sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "bus"); 378 sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "bus");
378 } 379 }
379 } 380 }
@@ -408,6 +409,7 @@ void bus_attach_device(struct device * dev)
408void bus_remove_device(struct device * dev) 409void bus_remove_device(struct device * dev)
409{ 410{
410 if (dev->bus) { 411 if (dev->bus) {
412 sysfs_remove_link(&dev->kobj, "subsystem");
411 sysfs_remove_link(&dev->kobj, "bus"); 413 sysfs_remove_link(&dev->kobj, "bus");
412 sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id); 414 sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id);
413 device_remove_attrs(dev->bus, dev); 415 device_remove_attrs(dev->bus, dev);
diff --git a/drivers/base/class.c b/drivers/base/class.c
index 50e841a33af0..9aa127460262 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -561,6 +561,7 @@ int class_device_add(struct class_device *class_dev)
561 goto out2; 561 goto out2;
562 562
563 /* add the needed attributes to this device */ 563 /* add the needed attributes to this device */
564 sysfs_create_link(&class_dev->kobj, &parent_class->subsys.kset.kobj, "subsystem");
564 class_dev->uevent_attr.attr.name = "uevent"; 565 class_dev->uevent_attr.attr.name = "uevent";
565 class_dev->uevent_attr.attr.mode = S_IWUSR; 566 class_dev->uevent_attr.attr.mode = S_IWUSR;
566 class_dev->uevent_attr.attr.owner = parent_class->owner; 567 class_dev->uevent_attr.attr.owner = parent_class->owner;
@@ -737,6 +738,7 @@ void class_device_del(struct class_device *class_dev)
737 sysfs_remove_link(&class_dev->kobj, "device"); 738 sysfs_remove_link(&class_dev->kobj, "device");
738 sysfs_remove_link(&class_dev->dev->kobj, class_name); 739 sysfs_remove_link(&class_dev->dev->kobj, class_name);
739 } 740 }
741 sysfs_remove_link(&class_dev->kobj, "subsystem");
740 class_device_remove_file(class_dev, &class_dev->uevent_attr); 742 class_device_remove_file(class_dev, &class_dev->uevent_attr);
741 if (class_dev->devt_attr) 743 if (class_dev->devt_attr)
742 class_device_remove_file(class_dev, class_dev->devt_attr); 744 class_device_remove_file(class_dev, class_dev->devt_attr);
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 252cf403f891..cc8bb97427d0 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -319,9 +319,12 @@ int device_add(struct device *dev)
319 dev->devt_attr = attr; 319 dev->devt_attr = attr;
320 } 320 }
321 321
322 if (dev->class) 322 if (dev->class) {
323 sysfs_create_link(&dev->kobj, &dev->class->subsys.kset.kobj,
324 "subsystem");
323 sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj, 325 sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj,
324 dev->bus_id); 326 dev->bus_id);
327 }
325 328
326 if ((error = device_pm_add(dev))) 329 if ((error = device_pm_add(dev)))
327 goto PMError; 330 goto PMError;
@@ -422,8 +425,10 @@ void device_del(struct device * dev)
422 klist_del(&dev->knode_parent); 425 klist_del(&dev->knode_parent);
423 if (dev->devt_attr) 426 if (dev->devt_attr)
424 device_remove_file(dev, dev->devt_attr); 427 device_remove_file(dev, dev->devt_attr);
425 if (dev->class) 428 if (dev->class) {
429 sysfs_remove_link(&dev->kobj, "subsystem");
426 sysfs_remove_link(&dev->class->subsys.kset.kobj, dev->bus_id); 430 sysfs_remove_link(&dev->class->subsys.kset.kobj, dev->bus_id);
431 }
427 device_remove_file(dev, &dev->uevent_attr); 432 device_remove_file(dev, &dev->uevent_attr);
428 433
429 /* Notify the platform of the removal, in case they 434 /* Notify the platform of the removal, in case they
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index 7ef1f094de91..8851b81e7c5a 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -329,6 +329,7 @@ void delete_partition(struct gendisk *disk, int part)
329 p->ios[0] = p->ios[1] = 0; 329 p->ios[0] = p->ios[1] = 0;
330 p->sectors[0] = p->sectors[1] = 0; 330 p->sectors[0] = p->sectors[1] = 0;
331 devfs_remove("%s/part%d", disk->devfs_name, part); 331 devfs_remove("%s/part%d", disk->devfs_name, part);
332 sysfs_remove_link(&p->kobj, "subsystem");
332 if (p->holder_dir) 333 if (p->holder_dir)
333 kobject_unregister(p->holder_dir); 334 kobject_unregister(p->holder_dir);
334 kobject_uevent(&p->kobj, KOBJ_REMOVE); 335 kobject_uevent(&p->kobj, KOBJ_REMOVE);
@@ -363,6 +364,7 @@ void add_partition(struct gendisk *disk, int part, sector_t start, sector_t len)
363 kobject_add(&p->kobj); 364 kobject_add(&p->kobj);
364 if (!disk->part_uevent_suppress) 365 if (!disk->part_uevent_suppress)
365 kobject_uevent(&p->kobj, KOBJ_ADD); 366 kobject_uevent(&p->kobj, KOBJ_ADD);
367 sysfs_create_link(&p->kobj, &block_subsys.kset.kobj, "subsystem");
366 partition_sysfs_add_subdir(p); 368 partition_sysfs_add_subdir(p);
367 disk->part[part-1] = p; 369 disk->part[part-1] = p;
368} 370}
@@ -398,6 +400,7 @@ static void disk_sysfs_symlinks(struct gendisk *disk)
398 kfree(disk_name); 400 kfree(disk_name);
399 } 401 }
400 } 402 }
403 sysfs_create_link(&disk->kobj, &block_subsys.kset.kobj, "subsystem");
401} 404}
402 405
403/* Not exported, helper to add_disk(). */ 406/* Not exported, helper to add_disk(). */
@@ -548,5 +551,6 @@ void del_gendisk(struct gendisk *disk)
548 put_device(disk->driverfs_dev); 551 put_device(disk->driverfs_dev);
549 disk->driverfs_dev = NULL; 552 disk->driverfs_dev = NULL;
550 } 553 }
554 sysfs_remove_link(&disk->kobj, "subsystem");
551 kobject_del(&disk->kobj); 555 kobject_del(&disk->kobj);
552} 556}