diff options
-rw-r--r-- | fs/partitions/check.c | 36 | ||||
-rw-r--r-- | include/linux/genhd.h | 7 |
2 files changed, 43 insertions, 0 deletions
diff --git a/fs/partitions/check.c b/fs/partitions/check.c index f924f459bdb8..60523cea7136 100644 --- a/fs/partitions/check.c +++ b/fs/partitions/check.c | |||
@@ -297,6 +297,30 @@ struct kobj_type ktype_part = { | |||
297 | .sysfs_ops = &part_sysfs_ops, | 297 | .sysfs_ops = &part_sysfs_ops, |
298 | }; | 298 | }; |
299 | 299 | ||
300 | #ifdef CONFIG_SYSFS | ||
301 | static inline void partition_sysfs_add_subdir(struct hd_struct *p) | ||
302 | { | ||
303 | struct kobject *k; | ||
304 | |||
305 | k = kobject_get(&p->kobj); | ||
306 | p->holder_dir = kobject_add_dir(k, "holders"); | ||
307 | kobject_put(k); | ||
308 | } | ||
309 | |||
310 | static inline void disk_sysfs_add_subdirs(struct gendisk *disk) | ||
311 | { | ||
312 | struct kobject *k; | ||
313 | |||
314 | k = kobject_get(&disk->kobj); | ||
315 | disk->holder_dir = kobject_add_dir(k, "holders"); | ||
316 | disk->slave_dir = kobject_add_dir(k, "slaves"); | ||
317 | kobject_put(k); | ||
318 | } | ||
319 | #else | ||
320 | #define partition_sysfs_add_subdir(x) do { } while (0) | ||
321 | #define disk_sysfs_add_subdirs(x) do { } while (0) | ||
322 | #endif | ||
323 | |||
300 | void delete_partition(struct gendisk *disk, int part) | 324 | void delete_partition(struct gendisk *disk, int part) |
301 | { | 325 | { |
302 | struct hd_struct *p = disk->part[part-1]; | 326 | struct hd_struct *p = disk->part[part-1]; |
@@ -310,6 +334,10 @@ void delete_partition(struct gendisk *disk, int part) | |||
310 | p->ios[0] = p->ios[1] = 0; | 334 | p->ios[0] = p->ios[1] = 0; |
311 | p->sectors[0] = p->sectors[1] = 0; | 335 | p->sectors[0] = p->sectors[1] = 0; |
312 | devfs_remove("%s/part%d", disk->devfs_name, part); | 336 | devfs_remove("%s/part%d", disk->devfs_name, part); |
337 | #ifdef CONFIG_SYSFS | ||
338 | if (p->holder_dir) | ||
339 | kobject_unregister(p->holder_dir); | ||
340 | #endif | ||
313 | kobject_unregister(&p->kobj); | 341 | kobject_unregister(&p->kobj); |
314 | } | 342 | } |
315 | 343 | ||
@@ -337,6 +365,7 @@ void add_partition(struct gendisk *disk, int part, sector_t start, sector_t len) | |||
337 | p->kobj.parent = &disk->kobj; | 365 | p->kobj.parent = &disk->kobj; |
338 | p->kobj.ktype = &ktype_part; | 366 | p->kobj.ktype = &ktype_part; |
339 | kobject_register(&p->kobj); | 367 | kobject_register(&p->kobj); |
368 | partition_sysfs_add_subdir(p); | ||
340 | disk->part[part-1] = p; | 369 | disk->part[part-1] = p; |
341 | } | 370 | } |
342 | 371 | ||
@@ -383,6 +412,7 @@ void register_disk(struct gendisk *disk) | |||
383 | if ((err = kobject_add(&disk->kobj))) | 412 | if ((err = kobject_add(&disk->kobj))) |
384 | return; | 413 | return; |
385 | disk_sysfs_symlinks(disk); | 414 | disk_sysfs_symlinks(disk); |
415 | disk_sysfs_add_subdirs(disk); | ||
386 | kobject_uevent(&disk->kobj, KOBJ_ADD); | 416 | kobject_uevent(&disk->kobj, KOBJ_ADD); |
387 | 417 | ||
388 | /* No minors to use for partitions */ | 418 | /* No minors to use for partitions */ |
@@ -483,6 +513,12 @@ void del_gendisk(struct gendisk *disk) | |||
483 | 513 | ||
484 | devfs_remove_disk(disk); | 514 | devfs_remove_disk(disk); |
485 | 515 | ||
516 | #ifdef CONFIG_SYSFS | ||
517 | if (disk->holder_dir) | ||
518 | kobject_unregister(disk->holder_dir); | ||
519 | if (disk->slave_dir) | ||
520 | kobject_unregister(disk->slave_dir); | ||
521 | #endif | ||
486 | if (disk->driverfs_dev) { | 522 | if (disk->driverfs_dev) { |
487 | char *disk_name = make_block_name(disk); | 523 | char *disk_name = make_block_name(disk); |
488 | sysfs_remove_link(&disk->kobj, "device"); | 524 | sysfs_remove_link(&disk->kobj, "device"); |
diff --git a/include/linux/genhd.h b/include/linux/genhd.h index fd647fde5ec1..eea61cc8fac1 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h | |||
@@ -78,6 +78,9 @@ struct hd_struct { | |||
78 | sector_t start_sect; | 78 | sector_t start_sect; |
79 | sector_t nr_sects; | 79 | sector_t nr_sects; |
80 | struct kobject kobj; | 80 | struct kobject kobj; |
81 | #ifdef CONFIG_SYSFS | ||
82 | struct kobject *holder_dir; | ||
83 | #endif | ||
81 | unsigned ios[2], sectors[2]; /* READs and WRITEs */ | 84 | unsigned ios[2], sectors[2]; /* READs and WRITEs */ |
82 | int policy, partno; | 85 | int policy, partno; |
83 | }; | 86 | }; |
@@ -114,6 +117,10 @@ struct gendisk { | |||
114 | int number; /* more of the same */ | 117 | int number; /* more of the same */ |
115 | struct device *driverfs_dev; | 118 | struct device *driverfs_dev; |
116 | struct kobject kobj; | 119 | struct kobject kobj; |
120 | #ifdef CONFIG_SYSFS | ||
121 | struct kobject *holder_dir; | ||
122 | struct kobject *slave_dir; | ||
123 | #endif | ||
117 | 124 | ||
118 | struct timer_rand_state *random; | 125 | struct timer_rand_state *random; |
119 | int policy; | 126 | int policy; |