浏览代码

[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>
Kay Sievers 19 年之前
父节点
当前提交
b9d9c82b4d
共有 5 个文件被更改,包括 17 次插入7 次删除
  1. 2 5
      block/genhd.c
  2. 2 0
      drivers/base/bus.c
  3. 2 0
      drivers/base/class.c
  4. 7 2
      drivers/base/core.c
  5. 4 0
      fs/partitions/check.c

+ 2 - 5
block/genhd.c

@@ -17,8 +17,7 @@
 #include <linux/buffer_head.h>
 #include <linux/buffer_head.h>
 #include <linux/mutex.h>
 #include <linux/mutex.h>
 
 
-static struct subsystem block_subsys;
-
+struct subsystem block_subsys;
 static DEFINE_MUTEX(block_subsys_lock);
 static DEFINE_MUTEX(block_subsys_lock);
 
 
 /*
 /*
@@ -511,9 +510,7 @@ static struct kset_uevent_ops block_uevent_ops = {
 	.uevent		= block_uevent,
 	.uevent		= block_uevent,
 };
 };
 
 
-/* declare block_subsys. */
-static decl_subsys(block, &ktype_block, &block_uevent_ops);
-
+decl_subsys(block, &ktype_block, &block_uevent_ops);
 
 
 /*
 /*
  * aggregate disk stat collector.  Uses the same stats that the sysfs
  * aggregate disk stat collector.  Uses the same stats that the sysfs

+ 2 - 0
drivers/base/bus.c

@@ -374,6 +374,7 @@ int bus_add_device(struct device * dev)
 		error = device_add_attrs(bus, dev);
 		error = device_add_attrs(bus, dev);
 		if (!error) {
 		if (!error) {
 			sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id);
 			sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id);
+			sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "subsystem");
 			sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "bus");
 			sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "bus");
 		}
 		}
 	}
 	}
@@ -408,6 +409,7 @@ void bus_attach_device(struct device * dev)
 void bus_remove_device(struct device * dev)
 void bus_remove_device(struct device * dev)
 {
 {
 	if (dev->bus) {
 	if (dev->bus) {
+		sysfs_remove_link(&dev->kobj, "subsystem");
 		sysfs_remove_link(&dev->kobj, "bus");
 		sysfs_remove_link(&dev->kobj, "bus");
 		sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id);
 		sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id);
 		device_remove_attrs(dev->bus, dev);
 		device_remove_attrs(dev->bus, dev);

+ 2 - 0
drivers/base/class.c

@@ -561,6 +561,7 @@ int class_device_add(struct class_device *class_dev)
 		goto out2;
 		goto out2;
 
 
 	/* add the needed attributes to this device */
 	/* add the needed attributes to this device */
+	sysfs_create_link(&class_dev->kobj, &parent_class->subsys.kset.kobj, "subsystem");
 	class_dev->uevent_attr.attr.name = "uevent";
 	class_dev->uevent_attr.attr.name = "uevent";
 	class_dev->uevent_attr.attr.mode = S_IWUSR;
 	class_dev->uevent_attr.attr.mode = S_IWUSR;
 	class_dev->uevent_attr.attr.owner = parent_class->owner;
 	class_dev->uevent_attr.attr.owner = parent_class->owner;
@@ -737,6 +738,7 @@ void class_device_del(struct class_device *class_dev)
 		sysfs_remove_link(&class_dev->kobj, "device");
 		sysfs_remove_link(&class_dev->kobj, "device");
 		sysfs_remove_link(&class_dev->dev->kobj, class_name);
 		sysfs_remove_link(&class_dev->dev->kobj, class_name);
 	}
 	}
+	sysfs_remove_link(&class_dev->kobj, "subsystem");
 	class_device_remove_file(class_dev, &class_dev->uevent_attr);
 	class_device_remove_file(class_dev, &class_dev->uevent_attr);
 	if (class_dev->devt_attr)
 	if (class_dev->devt_attr)
 		class_device_remove_file(class_dev, class_dev->devt_attr);
 		class_device_remove_file(class_dev, class_dev->devt_attr);

+ 7 - 2
drivers/base/core.c

@@ -319,9 +319,12 @@ int device_add(struct device *dev)
 		dev->devt_attr = attr;
 		dev->devt_attr = attr;
 	}
 	}
 
 
-	if (dev->class)
+	if (dev->class) {
+		sysfs_create_link(&dev->kobj, &dev->class->subsys.kset.kobj,
+				  "subsystem");
 		sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj,
 		sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj,
 				  dev->bus_id);
 				  dev->bus_id);
+	}
 
 
 	if ((error = device_pm_add(dev)))
 	if ((error = device_pm_add(dev)))
 		goto PMError;
 		goto PMError;
@@ -422,8 +425,10 @@ void device_del(struct device * dev)
 		klist_del(&dev->knode_parent);
 		klist_del(&dev->knode_parent);
 	if (dev->devt_attr)
 	if (dev->devt_attr)
 		device_remove_file(dev, dev->devt_attr);
 		device_remove_file(dev, dev->devt_attr);
-	if (dev->class)
+	if (dev->class) {
+		sysfs_remove_link(&dev->kobj, "subsystem");
 		sysfs_remove_link(&dev->class->subsys.kset.kobj, dev->bus_id);
 		sysfs_remove_link(&dev->class->subsys.kset.kobj, dev->bus_id);
+	}
 	device_remove_file(dev, &dev->uevent_attr);
 	device_remove_file(dev, &dev->uevent_attr);
 
 
 	/* Notify the platform of the removal, in case they
 	/* Notify the platform of the removal, in case they

+ 4 - 0
fs/partitions/check.c

@@ -329,6 +329,7 @@ void delete_partition(struct gendisk *disk, int part)
 	p->ios[0] = p->ios[1] = 0;
 	p->ios[0] = p->ios[1] = 0;
 	p->sectors[0] = p->sectors[1] = 0;
 	p->sectors[0] = p->sectors[1] = 0;
 	devfs_remove("%s/part%d", disk->devfs_name, part);
 	devfs_remove("%s/part%d", disk->devfs_name, part);
+	sysfs_remove_link(&p->kobj, "subsystem");
 	if (p->holder_dir)
 	if (p->holder_dir)
 		kobject_unregister(p->holder_dir);
 		kobject_unregister(p->holder_dir);
 	kobject_uevent(&p->kobj, KOBJ_REMOVE);
 	kobject_uevent(&p->kobj, KOBJ_REMOVE);
@@ -363,6 +364,7 @@ void add_partition(struct gendisk *disk, int part, sector_t start, sector_t len)
 	kobject_add(&p->kobj);
 	kobject_add(&p->kobj);
 	if (!disk->part_uevent_suppress)
 	if (!disk->part_uevent_suppress)
 		kobject_uevent(&p->kobj, KOBJ_ADD);
 		kobject_uevent(&p->kobj, KOBJ_ADD);
+	sysfs_create_link(&p->kobj, &block_subsys.kset.kobj, "subsystem");
 	partition_sysfs_add_subdir(p);
 	partition_sysfs_add_subdir(p);
 	disk->part[part-1] = p;
 	disk->part[part-1] = p;
 }
 }
@@ -398,6 +400,7 @@ static void disk_sysfs_symlinks(struct gendisk *disk)
 			kfree(disk_name);
 			kfree(disk_name);
 		}
 		}
 	}
 	}
+	sysfs_create_link(&disk->kobj, &block_subsys.kset.kobj, "subsystem");
 }
 }
 
 
 /* Not exported, helper to add_disk(). */
 /* Not exported, helper to add_disk(). */
@@ -548,5 +551,6 @@ void del_gendisk(struct gendisk *disk)
 		put_device(disk->driverfs_dev);
 		put_device(disk->driverfs_dev);
 		disk->driverfs_dev = NULL;
 		disk->driverfs_dev = NULL;
 	}
 	}
+	sysfs_remove_link(&disk->kobj, "subsystem");
 	kobject_del(&disk->kobj);
 	kobject_del(&disk->kobj);
 }
 }