diff options
author | Kay Sievers <kay.sievers@vrfy.org> | 2007-05-21 16:08:01 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2008-01-24 23:40:36 -0500 |
commit | edfaa7c36574f1bf09c65ad602412db9da5f96bf (patch) | |
tree | d591b80ff9229e4845e41d68e2f4c5aadb017027 /block/genhd.c | |
parent | 09f82ea92822a7bbb7e816508abbda47ed54a77f (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 'block/genhd.c')
-rw-r--r-- | block/genhd.c | 416 |
1 files changed, 183 insertions, 233 deletions
diff --git a/block/genhd.c b/block/genhd.c index 69aa7389d484..5e4ab4b37d9f 100644 --- a/block/genhd.c +++ b/block/genhd.c | |||
@@ -17,9 +17,10 @@ | |||
17 | #include <linux/buffer_head.h> | 17 | #include <linux/buffer_head.h> |
18 | #include <linux/mutex.h> | 18 | #include <linux/mutex.h> |
19 | 19 | ||
20 | struct kset *block_kset; | 20 | static DEFINE_MUTEX(block_class_lock); |
21 | static struct kset_uevent_ops block_uevent_ops; | 21 | #ifndef CONFIG_SYSFS_DEPRECATED |
22 | static DEFINE_MUTEX(block_subsys_lock); | 22 | struct kobject *block_depr; |
23 | #endif | ||
23 | 24 | ||
24 | /* | 25 | /* |
25 | * Can be deleted altogether. Later. | 26 | * Can be deleted altogether. Later. |
@@ -38,19 +39,17 @@ static inline int major_to_index(int major) | |||
38 | } | 39 | } |
39 | 40 | ||
40 | #ifdef CONFIG_PROC_FS | 41 | #ifdef CONFIG_PROC_FS |
41 | |||
42 | void blkdev_show(struct seq_file *f, off_t offset) | 42 | void blkdev_show(struct seq_file *f, off_t offset) |
43 | { | 43 | { |
44 | struct blk_major_name *dp; | 44 | struct blk_major_name *dp; |
45 | 45 | ||
46 | if (offset < BLKDEV_MAJOR_HASH_SIZE) { | 46 | if (offset < BLKDEV_MAJOR_HASH_SIZE) { |
47 | mutex_lock(&block_subsys_lock); | 47 | mutex_lock(&block_class_lock); |
48 | for (dp = major_names[offset]; dp; dp = dp->next) | 48 | for (dp = major_names[offset]; dp; dp = dp->next) |
49 | seq_printf(f, "%3d %s\n", dp->major, dp->name); | 49 | seq_printf(f, "%3d %s\n", dp->major, dp->name); |
50 | mutex_unlock(&block_subsys_lock); | 50 | mutex_unlock(&block_class_lock); |
51 | } | 51 | } |
52 | } | 52 | } |
53 | |||
54 | #endif /* CONFIG_PROC_FS */ | 53 | #endif /* CONFIG_PROC_FS */ |
55 | 54 | ||
56 | int register_blkdev(unsigned int major, const char *name) | 55 | int register_blkdev(unsigned int major, const char *name) |
@@ -58,7 +57,7 @@ int register_blkdev(unsigned int major, const char *name) | |||
58 | struct blk_major_name **n, *p; | 57 | struct blk_major_name **n, *p; |
59 | int index, ret = 0; | 58 | int index, ret = 0; |
60 | 59 | ||
61 | mutex_lock(&block_subsys_lock); | 60 | mutex_lock(&block_class_lock); |
62 | 61 | ||
63 | /* temporary */ | 62 | /* temporary */ |
64 | if (major == 0) { | 63 | if (major == 0) { |
@@ -103,7 +102,7 @@ int register_blkdev(unsigned int major, const char *name) | |||
103 | kfree(p); | 102 | kfree(p); |
104 | } | 103 | } |
105 | out: | 104 | out: |
106 | mutex_unlock(&block_subsys_lock); | 105 | mutex_unlock(&block_class_lock); |
107 | return ret; | 106 | return ret; |
108 | } | 107 | } |
109 | 108 | ||
@@ -115,7 +114,7 @@ void unregister_blkdev(unsigned int major, const char *name) | |||
115 | struct blk_major_name *p = NULL; | 114 | struct blk_major_name *p = NULL; |
116 | int index = major_to_index(major); | 115 | int index = major_to_index(major); |
117 | 116 | ||
118 | mutex_lock(&block_subsys_lock); | 117 | mutex_lock(&block_class_lock); |
119 | for (n = &major_names[index]; *n; n = &(*n)->next) | 118 | for (n = &major_names[index]; *n; n = &(*n)->next) |
120 | if ((*n)->major == major) | 119 | if ((*n)->major == major) |
121 | break; | 120 | break; |
@@ -125,7 +124,7 @@ void unregister_blkdev(unsigned int major, const char *name) | |||
125 | p = *n; | 124 | p = *n; |
126 | *n = p->next; | 125 | *n = p->next; |
127 | } | 126 | } |
128 | mutex_unlock(&block_subsys_lock); | 127 | mutex_unlock(&block_class_lock); |
129 | kfree(p); | 128 | kfree(p); |
130 | } | 129 | } |
131 | 130 | ||
@@ -138,29 +137,30 @@ static struct kobj_map *bdev_map; | |||
138 | * range must be nonzero | 137 | * range must be nonzero |
139 | * The hash chain is sorted on range, so that subranges can override. | 138 | * The hash chain is sorted on range, so that subranges can override. |
140 | */ | 139 | */ |
141 | void blk_register_region(dev_t dev, unsigned long range, struct module *module, | 140 | void blk_register_region(dev_t devt, unsigned long range, struct module *module, |
142 | struct kobject *(*probe)(dev_t, int *, void *), | 141 | struct kobject *(*probe)(dev_t, int *, void *), |
143 | int (*lock)(dev_t, void *), void *data) | 142 | int (*lock)(dev_t, void *), void *data) |
144 | { | 143 | { |
145 | kobj_map(bdev_map, dev, range, module, probe, lock, data); | 144 | kobj_map(bdev_map, devt, range, module, probe, lock, data); |
146 | } | 145 | } |
147 | 146 | ||
148 | EXPORT_SYMBOL(blk_register_region); | 147 | EXPORT_SYMBOL(blk_register_region); |
149 | 148 | ||
150 | void blk_unregister_region(dev_t dev, unsigned long range) | 149 | void blk_unregister_region(dev_t devt, unsigned long range) |
151 | { | 150 | { |
152 | kobj_unmap(bdev_map, dev, range); | 151 | kobj_unmap(bdev_map, devt, range); |
153 | } | 152 | } |
154 | 153 | ||
155 | EXPORT_SYMBOL(blk_unregister_region); | 154 | EXPORT_SYMBOL(blk_unregister_region); |
156 | 155 | ||
157 | static struct kobject *exact_match(dev_t dev, int *part, void *data) | 156 | static struct kobject *exact_match(dev_t devt, int *part, void *data) |
158 | { | 157 | { |
159 | struct gendisk *p = data; | 158 | struct gendisk *p = data; |
160 | return &p->kobj; | 159 | |
160 | return &p->dev.kobj; | ||
161 | } | 161 | } |
162 | 162 | ||
163 | static int exact_lock(dev_t dev, void *data) | 163 | static int exact_lock(dev_t devt, void *data) |
164 | { | 164 | { |
165 | struct gendisk *p = data; | 165 | struct gendisk *p = data; |
166 | 166 | ||
@@ -195,8 +195,6 @@ void unlink_gendisk(struct gendisk *disk) | |||
195 | disk->minors); | 195 | disk->minors); |
196 | } | 196 | } |
197 | 197 | ||
198 | #define to_disk(obj) container_of(obj,struct gendisk,kobj) | ||
199 | |||
200 | /** | 198 | /** |
201 | * get_gendisk - get partitioning information for a given device | 199 | * get_gendisk - get partitioning information for a given device |
202 | * @dev: device to get partitioning information for | 200 | * @dev: device to get partitioning information for |
@@ -204,10 +202,12 @@ void unlink_gendisk(struct gendisk *disk) | |||
204 | * This function gets the structure containing partitioning | 202 | * This function gets the structure containing partitioning |
205 | * information for the given device @dev. | 203 | * information for the given device @dev. |
206 | */ | 204 | */ |
207 | struct gendisk *get_gendisk(dev_t dev, int *part) | 205 | struct gendisk *get_gendisk(dev_t devt, int *part) |
208 | { | 206 | { |
209 | struct kobject *kobj = kobj_lookup(bdev_map, dev, part); | 207 | struct kobject *kobj = kobj_lookup(bdev_map, devt, part); |
210 | return kobj ? to_disk(kobj) : NULL; | 208 | struct device *dev = kobj_to_dev(kobj); |
209 | |||
210 | return kobj ? dev_to_disk(dev) : NULL; | ||
211 | } | 211 | } |
212 | 212 | ||
213 | /* | 213 | /* |
@@ -217,13 +217,17 @@ struct gendisk *get_gendisk(dev_t dev, int *part) | |||
217 | */ | 217 | */ |
218 | void __init printk_all_partitions(void) | 218 | void __init printk_all_partitions(void) |
219 | { | 219 | { |
220 | int n; | 220 | struct device *dev; |
221 | struct gendisk *sgp; | 221 | struct gendisk *sgp; |
222 | char buf[BDEVNAME_SIZE]; | ||
223 | int n; | ||
222 | 224 | ||
223 | mutex_lock(&block_subsys_lock); | 225 | mutex_lock(&block_class_lock); |
224 | /* For each block device... */ | 226 | /* For each block device... */ |
225 | list_for_each_entry(sgp, &block_kset->list, kobj.entry) { | 227 | list_for_each_entry(dev, &block_class.devices, node) { |
226 | char buf[BDEVNAME_SIZE]; | 228 | if (dev->type != &disk_type) |
229 | continue; | ||
230 | sgp = dev_to_disk(dev); | ||
227 | /* | 231 | /* |
228 | * Don't show empty devices or things that have been surpressed | 232 | * Don't show empty devices or things that have been surpressed |
229 | */ | 233 | */ |
@@ -256,38 +260,46 @@ void __init printk_all_partitions(void) | |||
256 | sgp->major, n + 1 + sgp->first_minor, | 260 | sgp->major, n + 1 + sgp->first_minor, |
257 | (unsigned long long)sgp->part[n]->nr_sects >> 1, | 261 | (unsigned long long)sgp->part[n]->nr_sects >> 1, |
258 | disk_name(sgp, n + 1, buf)); | 262 | disk_name(sgp, n + 1, buf)); |
259 | } /* partition subloop */ | 263 | } |
260 | } /* Block device loop */ | 264 | } |
261 | 265 | ||
262 | mutex_unlock(&block_subsys_lock); | 266 | mutex_unlock(&block_class_lock); |
263 | return; | ||
264 | } | 267 | } |
265 | 268 | ||
266 | #ifdef CONFIG_PROC_FS | 269 | #ifdef CONFIG_PROC_FS |
267 | /* iterator */ | 270 | /* iterator */ |
268 | static void *part_start(struct seq_file *part, loff_t *pos) | 271 | static void *part_start(struct seq_file *part, loff_t *pos) |
269 | { | 272 | { |
270 | struct list_head *p; | 273 | loff_t k = *pos; |
271 | loff_t l = *pos; | 274 | struct device *dev; |
272 | 275 | ||
273 | mutex_lock(&block_subsys_lock); | 276 | mutex_lock(&block_class_lock); |
274 | list_for_each(p, &block_kset->list) | 277 | list_for_each_entry(dev, &block_class.devices, node) { |
275 | if (!l--) | 278 | if (dev->type != &disk_type) |
276 | return list_entry(p, struct gendisk, kobj.entry); | 279 | continue; |
280 | if (!k--) | ||
281 | return dev_to_disk(dev); | ||
282 | } | ||
277 | return NULL; | 283 | return NULL; |
278 | } | 284 | } |
279 | 285 | ||
280 | static void *part_next(struct seq_file *part, void *v, loff_t *pos) | 286 | static void *part_next(struct seq_file *part, void *v, loff_t *pos) |
281 | { | 287 | { |
282 | struct list_head *p = ((struct gendisk *)v)->kobj.entry.next; | 288 | struct gendisk *gp = v; |
289 | struct device *dev; | ||
283 | ++*pos; | 290 | ++*pos; |
284 | return p==&block_kset->list ? NULL : | 291 | list_for_each_entry(dev, &gp->dev.node, node) { |
285 | list_entry(p, struct gendisk, kobj.entry); | 292 | if (&dev->node == &block_class.devices) |
293 | return NULL; | ||
294 | if (dev->type == &disk_type) | ||
295 | return dev_to_disk(dev); | ||
296 | } | ||
297 | return NULL; | ||
286 | } | 298 | } |
287 | 299 | ||
288 | static void part_stop(struct seq_file *part, void *v) | 300 | static void part_stop(struct seq_file *part, void *v) |
289 | { | 301 | { |
290 | mutex_unlock(&block_subsys_lock); | 302 | mutex_unlock(&block_class_lock); |
291 | } | 303 | } |
292 | 304 | ||
293 | static int show_partition(struct seq_file *part, void *v) | 305 | static int show_partition(struct seq_file *part, void *v) |
@@ -296,7 +308,7 @@ static int show_partition(struct seq_file *part, void *v) | |||
296 | int n; | 308 | int n; |
297 | char buf[BDEVNAME_SIZE]; | 309 | char buf[BDEVNAME_SIZE]; |
298 | 310 | ||
299 | if (&sgp->kobj.entry == block_kset->list.next) | 311 | if (&sgp->dev.node == block_class.devices.next) |
300 | seq_puts(part, "major minor #blocks name\n\n"); | 312 | seq_puts(part, "major minor #blocks name\n\n"); |
301 | 313 | ||
302 | /* Don't show non-partitionable removeable devices or empty devices */ | 314 | /* Don't show non-partitionable removeable devices or empty devices */ |
@@ -326,109 +338,81 @@ static int show_partition(struct seq_file *part, void *v) | |||
326 | } | 338 | } |
327 | 339 | ||
328 | struct seq_operations partitions_op = { | 340 | struct seq_operations partitions_op = { |
329 | .start =part_start, | 341 | .start = part_start, |
330 | .next = part_next, | 342 | .next = part_next, |
331 | .stop = part_stop, | 343 | .stop = part_stop, |
332 | .show = show_partition | 344 | .show = show_partition |
333 | }; | 345 | }; |
334 | #endif | 346 | #endif |
335 | 347 | ||
336 | 348 | ||
337 | extern int blk_dev_init(void); | 349 | extern int blk_dev_init(void); |
338 | 350 | ||
339 | static struct kobject *base_probe(dev_t dev, int *part, void *data) | 351 | static struct kobject *base_probe(dev_t devt, int *part, void *data) |
340 | { | 352 | { |
341 | if (request_module("block-major-%d-%d", MAJOR(dev), MINOR(dev)) > 0) | 353 | if (request_module("block-major-%d-%d", MAJOR(devt), MINOR(devt)) > 0) |
342 | /* Make old-style 2.4 aliases work */ | 354 | /* Make old-style 2.4 aliases work */ |
343 | request_module("block-major-%d", MAJOR(dev)); | 355 | request_module("block-major-%d", MAJOR(devt)); |
344 | return NULL; | 356 | return NULL; |
345 | } | 357 | } |
346 | 358 | ||
347 | static int __init genhd_device_init(void) | 359 | static int __init genhd_device_init(void) |
348 | { | 360 | { |
349 | bdev_map = kobj_map_init(base_probe, &block_subsys_lock); | 361 | class_register(&block_class); |
362 | bdev_map = kobj_map_init(base_probe, &block_class_lock); | ||
350 | blk_dev_init(); | 363 | blk_dev_init(); |
351 | block_kset = kset_create_and_add("block", &block_uevent_ops, NULL); | 364 | |
352 | if (!block_kset) { | 365 | #ifndef CONFIG_SYSFS_DEPRECATED |
353 | printk(KERN_WARNING "%s: kset_create error\n", __FUNCTION__); | 366 | /* create top-level block dir */ |
354 | return -ENOMEM; | 367 | block_depr = kobject_create_and_add("block", NULL); |
355 | } | 368 | #endif |
356 | return 0; | 369 | return 0; |
357 | } | 370 | } |
358 | 371 | ||
359 | subsys_initcall(genhd_device_init); | 372 | subsys_initcall(genhd_device_init); |
360 | 373 | ||
361 | 374 | static ssize_t disk_range_show(struct device *dev, | |
362 | 375 | struct device_attribute *attr, char *buf) | |
363 | /* | ||
364 | * kobject & sysfs bindings for block devices | ||
365 | */ | ||
366 | static ssize_t disk_attr_show(struct kobject *kobj, struct attribute *attr, | ||
367 | char *page) | ||
368 | { | 376 | { |
369 | struct gendisk *disk = to_disk(kobj); | 377 | struct gendisk *disk = dev_to_disk(dev); |
370 | struct disk_attribute *disk_attr = | ||
371 | container_of(attr,struct disk_attribute,attr); | ||
372 | ssize_t ret = -EIO; | ||
373 | 378 | ||
374 | if (disk_attr->show) | 379 | return sprintf(buf, "%d\n", disk->minors); |
375 | ret = disk_attr->show(disk,page); | ||
376 | return ret; | ||
377 | } | 380 | } |
378 | 381 | ||
379 | static ssize_t disk_attr_store(struct kobject * kobj, struct attribute * attr, | 382 | static ssize_t disk_removable_show(struct device *dev, |
380 | const char *page, size_t count) | 383 | struct device_attribute *attr, char *buf) |
381 | { | 384 | { |
382 | struct gendisk *disk = to_disk(kobj); | 385 | struct gendisk *disk = dev_to_disk(dev); |
383 | struct disk_attribute *disk_attr = | ||
384 | container_of(attr,struct disk_attribute,attr); | ||
385 | ssize_t ret = 0; | ||
386 | 386 | ||
387 | if (disk_attr->store) | 387 | return sprintf(buf, "%d\n", |
388 | ret = disk_attr->store(disk, page, count); | 388 | (disk->flags & GENHD_FL_REMOVABLE ? 1 : 0)); |
389 | return ret; | ||
390 | } | 389 | } |
391 | 390 | ||
392 | static struct sysfs_ops disk_sysfs_ops = { | 391 | static ssize_t disk_size_show(struct device *dev, |
393 | .show = &disk_attr_show, | 392 | struct device_attribute *attr, char *buf) |
394 | .store = &disk_attr_store, | ||
395 | }; | ||
396 | |||
397 | static ssize_t disk_uevent_store(struct gendisk * disk, | ||
398 | const char *buf, size_t count) | ||
399 | { | 393 | { |
400 | kobject_uevent(&disk->kobj, KOBJ_ADD); | 394 | struct gendisk *disk = dev_to_disk(dev); |
401 | return count; | ||
402 | } | ||
403 | static ssize_t disk_dev_read(struct gendisk * disk, char *page) | ||
404 | { | ||
405 | dev_t base = MKDEV(disk->major, disk->first_minor); | ||
406 | return print_dev_t(page, base); | ||
407 | } | ||
408 | static ssize_t disk_range_read(struct gendisk * disk, char *page) | ||
409 | { | ||
410 | return sprintf(page, "%d\n", disk->minors); | ||
411 | } | ||
412 | static ssize_t disk_removable_read(struct gendisk * disk, char *page) | ||
413 | { | ||
414 | return sprintf(page, "%d\n", | ||
415 | (disk->flags & GENHD_FL_REMOVABLE ? 1 : 0)); | ||
416 | 395 | ||
396 | return sprintf(buf, "%llu\n", (unsigned long long)get_capacity(disk)); | ||
417 | } | 397 | } |
418 | static ssize_t disk_size_read(struct gendisk * disk, char *page) | 398 | |
419 | { | 399 | static ssize_t disk_capability_show(struct device *dev, |
420 | return sprintf(page, "%llu\n", (unsigned long long)get_capacity(disk)); | 400 | struct device_attribute *attr, char *buf) |
421 | } | ||
422 | static ssize_t disk_capability_read(struct gendisk *disk, char *page) | ||
423 | { | 401 | { |
424 | return sprintf(page, "%x\n", disk->flags); | 402 | struct gendisk *disk = dev_to_disk(dev); |
403 | |||
404 | return sprintf(buf, "%x\n", disk->flags); | ||
425 | } | 405 | } |
426 | static ssize_t disk_stats_read(struct gendisk * disk, char *page) | 406 | |
407 | static ssize_t disk_stat_show(struct device *dev, | ||
408 | struct device_attribute *attr, char *buf) | ||
427 | { | 409 | { |
410 | struct gendisk *disk = dev_to_disk(dev); | ||
411 | |||
428 | preempt_disable(); | 412 | preempt_disable(); |
429 | disk_round_stats(disk); | 413 | disk_round_stats(disk); |
430 | preempt_enable(); | 414 | preempt_enable(); |
431 | return sprintf(page, | 415 | return sprintf(buf, |
432 | "%8lu %8lu %8llu %8u " | 416 | "%8lu %8lu %8llu %8u " |
433 | "%8lu %8lu %8llu %8u " | 417 | "%8lu %8lu %8llu %8u " |
434 | "%8u %8u %8u" | 418 | "%8u %8u %8u" |
@@ -445,40 +429,21 @@ static ssize_t disk_stats_read(struct gendisk * disk, char *page) | |||
445 | jiffies_to_msecs(disk_stat_read(disk, io_ticks)), | 429 | jiffies_to_msecs(disk_stat_read(disk, io_ticks)), |
446 | jiffies_to_msecs(disk_stat_read(disk, time_in_queue))); | 430 | jiffies_to_msecs(disk_stat_read(disk, time_in_queue))); |
447 | } | 431 | } |
448 | static struct disk_attribute disk_attr_uevent = { | ||
449 | .attr = {.name = "uevent", .mode = S_IWUSR }, | ||
450 | .store = disk_uevent_store | ||
451 | }; | ||
452 | static struct disk_attribute disk_attr_dev = { | ||
453 | .attr = {.name = "dev", .mode = S_IRUGO }, | ||
454 | .show = disk_dev_read | ||
455 | }; | ||
456 | static struct disk_attribute disk_attr_range = { | ||
457 | .attr = {.name = "range", .mode = S_IRUGO }, | ||
458 | .show = disk_range_read | ||
459 | }; | ||
460 | static struct disk_attribute disk_attr_removable = { | ||
461 | .attr = {.name = "removable", .mode = S_IRUGO }, | ||
462 | .show = disk_removable_read | ||
463 | }; | ||
464 | static struct disk_attribute disk_attr_size = { | ||
465 | .attr = {.name = "size", .mode = S_IRUGO }, | ||
466 | .show = disk_size_read | ||
467 | }; | ||
468 | static struct disk_attribute disk_attr_capability = { | ||
469 | .attr = {.name = "capability", .mode = S_IRUGO }, | ||
470 | .show = disk_capability_read | ||
471 | }; | ||
472 | static struct disk_attribute disk_attr_stat = { | ||
473 | .attr = {.name = "stat", .mode = S_IRUGO }, | ||
474 | .show = disk_stats_read | ||
475 | }; | ||
476 | 432 | ||
477 | #ifdef CONFIG_FAIL_MAKE_REQUEST | 433 | #ifdef CONFIG_FAIL_MAKE_REQUEST |
434 | static ssize_t disk_fail_show(struct device *dev, | ||
435 | struct device_attribute *attr, char *buf) | ||
436 | { | ||
437 | struct gendisk *disk = dev_to_disk(dev); | ||
438 | |||
439 | return sprintf(buf, "%d\n", disk->flags & GENHD_FL_FAIL ? 1 : 0); | ||
440 | } | ||
478 | 441 | ||
479 | static ssize_t disk_fail_store(struct gendisk * disk, | 442 | static ssize_t disk_fail_store(struct device *dev, |
443 | struct device_attribute *attr, | ||
480 | const char *buf, size_t count) | 444 | const char *buf, size_t count) |
481 | { | 445 | { |
446 | struct gendisk *disk = dev_to_disk(dev); | ||
482 | int i; | 447 | int i; |
483 | 448 | ||
484 | if (count > 0 && sscanf(buf, "%d", &i) > 0) { | 449 | if (count > 0 && sscanf(buf, "%d", &i) > 0) { |
@@ -490,134 +455,100 @@ static ssize_t disk_fail_store(struct gendisk * disk, | |||
490 | 455 | ||
491 | return count; | 456 | return count; |
492 | } | 457 | } |
493 | static ssize_t disk_fail_read(struct gendisk * disk, char *page) | ||
494 | { | ||
495 | return sprintf(page, "%d\n", disk->flags & GENHD_FL_FAIL ? 1 : 0); | ||
496 | } | ||
497 | static struct disk_attribute disk_attr_fail = { | ||
498 | .attr = {.name = "make-it-fail", .mode = S_IRUGO | S_IWUSR }, | ||
499 | .store = disk_fail_store, | ||
500 | .show = disk_fail_read | ||
501 | }; | ||
502 | 458 | ||
503 | #endif | 459 | #endif |
504 | 460 | ||
505 | static struct attribute * default_attrs[] = { | 461 | static DEVICE_ATTR(range, S_IRUGO, disk_range_show, NULL); |
506 | &disk_attr_uevent.attr, | 462 | static DEVICE_ATTR(removable, S_IRUGO, disk_removable_show, NULL); |
507 | &disk_attr_dev.attr, | 463 | static DEVICE_ATTR(size, S_IRUGO, disk_size_show, NULL); |
508 | &disk_attr_range.attr, | 464 | static DEVICE_ATTR(capability, S_IRUGO, disk_capability_show, NULL); |
509 | &disk_attr_removable.attr, | 465 | static DEVICE_ATTR(stat, S_IRUGO, disk_stat_show, NULL); |
510 | &disk_attr_size.attr, | ||
511 | &disk_attr_stat.attr, | ||
512 | &disk_attr_capability.attr, | ||
513 | #ifdef CONFIG_FAIL_MAKE_REQUEST | 466 | #ifdef CONFIG_FAIL_MAKE_REQUEST |
514 | &disk_attr_fail.attr, | 467 | static struct device_attribute dev_attr_fail = |
468 | __ATTR(make-it-fail, S_IRUGO|S_IWUSR, disk_fail_show, disk_fail_store); | ||
515 | #endif | 469 | #endif |
516 | NULL, | 470 | |
471 | static struct attribute *disk_attrs[] = { | ||
472 | &dev_attr_range.attr, | ||
473 | &dev_attr_removable.attr, | ||
474 | &dev_attr_size.attr, | ||
475 | &dev_attr_capability.attr, | ||
476 | &dev_attr_stat.attr, | ||
477 | #ifdef CONFIG_FAIL_MAKE_REQUEST | ||
478 | &dev_attr_fail.attr, | ||
479 | #endif | ||
480 | NULL | ||
481 | }; | ||
482 | |||
483 | static struct attribute_group disk_attr_group = { | ||
484 | .attrs = disk_attrs, | ||
485 | }; | ||
486 | |||
487 | static struct attribute_group *disk_attr_groups[] = { | ||
488 | &disk_attr_group, | ||
489 | NULL | ||
517 | }; | 490 | }; |
518 | 491 | ||
519 | static void disk_release(struct kobject * kobj) | 492 | static void disk_release(struct device *dev) |
520 | { | 493 | { |
521 | struct gendisk *disk = to_disk(kobj); | 494 | struct gendisk *disk = dev_to_disk(dev); |
495 | |||
522 | kfree(disk->random); | 496 | kfree(disk->random); |
523 | kfree(disk->part); | 497 | kfree(disk->part); |
524 | free_disk_stats(disk); | 498 | free_disk_stats(disk); |
525 | kfree(disk); | 499 | kfree(disk); |
526 | } | 500 | } |
527 | 501 | struct class block_class = { | |
528 | static struct kobj_type ktype_block = { | 502 | .name = "block", |
529 | .release = disk_release, | ||
530 | .sysfs_ops = &disk_sysfs_ops, | ||
531 | .default_attrs = default_attrs, | ||
532 | }; | 503 | }; |
533 | 504 | ||
534 | extern struct kobj_type ktype_part; | 505 | struct device_type disk_type = { |
535 | 506 | .name = "disk", | |
536 | static int block_uevent_filter(struct kset *kset, struct kobject *kobj) | 507 | .groups = disk_attr_groups, |
537 | { | 508 | .release = disk_release, |
538 | struct kobj_type *ktype = get_ktype(kobj); | ||
539 | |||
540 | return ((ktype == &ktype_block) || (ktype == &ktype_part)); | ||
541 | } | ||
542 | |||
543 | static int block_uevent(struct kset *kset, struct kobject *kobj, | ||
544 | struct kobj_uevent_env *env) | ||
545 | { | ||
546 | struct kobj_type *ktype = get_ktype(kobj); | ||
547 | struct device *physdev; | ||
548 | struct gendisk *disk; | ||
549 | struct hd_struct *part; | ||
550 | |||
551 | if (ktype == &ktype_block) { | ||
552 | disk = container_of(kobj, struct gendisk, kobj); | ||
553 | add_uevent_var(env, "MINOR=%u", disk->first_minor); | ||
554 | } else if (ktype == &ktype_part) { | ||
555 | disk = container_of(kobj->parent, struct gendisk, kobj); | ||
556 | part = container_of(kobj, struct hd_struct, kobj); | ||
557 | add_uevent_var(env, "MINOR=%u", | ||
558 | disk->first_minor + part->partno); | ||
559 | } else | ||
560 | return 0; | ||
561 | |||
562 | add_uevent_var(env, "MAJOR=%u", disk->major); | ||
563 | |||
564 | /* add physical device, backing this device */ | ||
565 | physdev = disk->driverfs_dev; | ||
566 | if (physdev) { | ||
567 | char *path = kobject_get_path(&physdev->kobj, GFP_KERNEL); | ||
568 | |||
569 | add_uevent_var(env, "PHYSDEVPATH=%s", path); | ||
570 | kfree(path); | ||
571 | |||
572 | if (physdev->bus) | ||
573 | add_uevent_var(env, "PHYSDEVBUS=%s", physdev->bus->name); | ||
574 | |||
575 | if (physdev->driver) | ||
576 | add_uevent_var(env, physdev->driver->name); | ||
577 | } | ||
578 | |||
579 | return 0; | ||
580 | } | ||
581 | |||
582 | static struct kset_uevent_ops block_uevent_ops = { | ||
583 | .filter = block_uevent_filter, | ||
584 | .uevent = block_uevent, | ||
585 | }; | 509 | }; |
586 | 510 | ||
587 | /* | 511 | /* |
588 | * aggregate disk stat collector. Uses the same stats that the sysfs | 512 | * aggregate disk stat collector. Uses the same stats that the sysfs |
589 | * entries do, above, but makes them available through one seq_file. | 513 | * entries do, above, but makes them available through one seq_file. |
590 | * Watching a few disks may be efficient through sysfs, but watching | ||
591 | * all of them will be more efficient through this interface. | ||
592 | * | 514 | * |
593 | * The output looks suspiciously like /proc/partitions with a bunch of | 515 | * The output looks suspiciously like /proc/partitions with a bunch of |
594 | * extra fields. | 516 | * extra fields. |
595 | */ | 517 | */ |
596 | 518 | ||
597 | /* iterator */ | ||
598 | static void *diskstats_start(struct seq_file *part, loff_t *pos) | 519 | static void *diskstats_start(struct seq_file *part, loff_t *pos) |
599 | { | 520 | { |
600 | loff_t k = *pos; | 521 | loff_t k = *pos; |
601 | struct list_head *p; | 522 | struct device *dev; |
602 | 523 | ||
603 | mutex_lock(&block_subsys_lock); | 524 | mutex_lock(&block_class_lock); |
604 | list_for_each(p, &block_kset->list) | 525 | list_for_each_entry(dev, &block_class.devices, node) { |
526 | if (dev->type != &disk_type) | ||
527 | continue; | ||
605 | if (!k--) | 528 | if (!k--) |
606 | return list_entry(p, struct gendisk, kobj.entry); | 529 | return dev_to_disk(dev); |
530 | } | ||
607 | return NULL; | 531 | return NULL; |
608 | } | 532 | } |
609 | 533 | ||
610 | static void *diskstats_next(struct seq_file *part, void *v, loff_t *pos) | 534 | static void *diskstats_next(struct seq_file *part, void *v, loff_t *pos) |
611 | { | 535 | { |
612 | struct list_head *p = ((struct gendisk *)v)->kobj.entry.next; | 536 | struct gendisk *gp = v; |
537 | struct device *dev; | ||
538 | |||
613 | ++*pos; | 539 | ++*pos; |
614 | return p==&block_kset->list ? NULL : | 540 | list_for_each_entry(dev, &gp->dev.node, node) { |
615 | list_entry(p, struct gendisk, kobj.entry); | 541 | if (&dev->node == &block_class.devices) |
542 | return NULL; | ||
543 | if (dev->type == &disk_type) | ||
544 | return dev_to_disk(dev); | ||
545 | } | ||
546 | return NULL; | ||
616 | } | 547 | } |
617 | 548 | ||
618 | static void diskstats_stop(struct seq_file *part, void *v) | 549 | static void diskstats_stop(struct seq_file *part, void *v) |
619 | { | 550 | { |
620 | mutex_unlock(&block_subsys_lock); | 551 | mutex_unlock(&block_class_lock); |
621 | } | 552 | } |
622 | 553 | ||
623 | static int diskstats_show(struct seq_file *s, void *v) | 554 | static int diskstats_show(struct seq_file *s, void *v) |
@@ -627,7 +558,7 @@ static int diskstats_show(struct seq_file *s, void *v) | |||
627 | int n = 0; | 558 | int n = 0; |
628 | 559 | ||
629 | /* | 560 | /* |
630 | if (&sgp->kobj.entry == block_kset->list.next) | 561 | if (&gp->dev.kobj.entry == block_class.devices.next) |
631 | seq_puts(s, "major minor name" | 562 | seq_puts(s, "major minor name" |
632 | " rio rmerge rsect ruse wio wmerge " | 563 | " rio rmerge rsect ruse wio wmerge " |
633 | "wsect wuse running use aveq" | 564 | "wsect wuse running use aveq" |
@@ -681,7 +612,7 @@ static void media_change_notify_thread(struct work_struct *work) | |||
681 | * set enviroment vars to indicate which event this is for | 612 | * set enviroment vars to indicate which event this is for |
682 | * so that user space will know to go check the media status. | 613 | * so that user space will know to go check the media status. |
683 | */ | 614 | */ |
684 | kobject_uevent_env(&gd->kobj, KOBJ_CHANGE, envp); | 615 | kobject_uevent_env(&gd->dev.kobj, KOBJ_CHANGE, envp); |
685 | put_device(gd->driverfs_dev); | 616 | put_device(gd->driverfs_dev); |
686 | } | 617 | } |
687 | 618 | ||
@@ -692,6 +623,25 @@ void genhd_media_change_notify(struct gendisk *disk) | |||
692 | } | 623 | } |
693 | EXPORT_SYMBOL_GPL(genhd_media_change_notify); | 624 | EXPORT_SYMBOL_GPL(genhd_media_change_notify); |
694 | 625 | ||
626 | dev_t blk_lookup_devt(const char *name) | ||
627 | { | ||
628 | struct device *dev; | ||
629 | dev_t devt = MKDEV(0, 0); | ||
630 | |||
631 | mutex_lock(&block_class_lock); | ||
632 | list_for_each_entry(dev, &block_class.devices, node) { | ||
633 | if (strcmp(dev->bus_id, name) == 0) { | ||
634 | devt = dev->devt; | ||
635 | break; | ||
636 | } | ||
637 | } | ||
638 | mutex_unlock(&block_class_lock); | ||
639 | |||
640 | return devt; | ||
641 | } | ||
642 | |||
643 | EXPORT_SYMBOL(blk_lookup_devt); | ||
644 | |||
695 | struct gendisk *alloc_disk(int minors) | 645 | struct gendisk *alloc_disk(int minors) |
696 | { | 646 | { |
697 | return alloc_disk_node(minors, -1); | 647 | return alloc_disk_node(minors, -1); |
@@ -719,10 +669,10 @@ struct gendisk *alloc_disk_node(int minors, int node_id) | |||
719 | } | 669 | } |
720 | } | 670 | } |
721 | disk->minors = minors; | 671 | disk->minors = minors; |
722 | disk->kobj.kset = block_kset; | ||
723 | disk->kobj.ktype = &ktype_block; | ||
724 | kobject_init(&disk->kobj); | ||
725 | rand_initialize_disk(disk); | 672 | rand_initialize_disk(disk); |
673 | disk->dev.class = &block_class; | ||
674 | disk->dev.type = &disk_type; | ||
675 | device_initialize(&disk->dev); | ||
726 | INIT_WORK(&disk->async_notify, | 676 | INIT_WORK(&disk->async_notify, |
727 | media_change_notify_thread); | 677 | media_change_notify_thread); |
728 | } | 678 | } |
@@ -742,7 +692,7 @@ struct kobject *get_disk(struct gendisk *disk) | |||
742 | owner = disk->fops->owner; | 692 | owner = disk->fops->owner; |
743 | if (owner && !try_module_get(owner)) | 693 | if (owner && !try_module_get(owner)) |
744 | return NULL; | 694 | return NULL; |
745 | kobj = kobject_get(&disk->kobj); | 695 | kobj = kobject_get(&disk->dev.kobj); |
746 | if (kobj == NULL) { | 696 | if (kobj == NULL) { |
747 | module_put(owner); | 697 | module_put(owner); |
748 | return NULL; | 698 | return NULL; |
@@ -756,7 +706,7 @@ EXPORT_SYMBOL(get_disk); | |||
756 | void put_disk(struct gendisk *disk) | 706 | void put_disk(struct gendisk *disk) |
757 | { | 707 | { |
758 | if (disk) | 708 | if (disk) |
759 | kobject_put(&disk->kobj); | 709 | kobject_put(&disk->dev.kobj); |
760 | } | 710 | } |
761 | 711 | ||
762 | EXPORT_SYMBOL(put_disk); | 712 | EXPORT_SYMBOL(put_disk); |