X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=block%2Fgenhd.c;h=e0ce23ac2ece84b24a283f9ae9203ec3291f2f78;hb=bcbc713470283bc82d043fd23b02e41a9eb8dee5;hp=10b9ac46c2da00ef2f7a98ff667cce846df1a99d;hpb=5c6f35c5ece8f130cd8ec9ba0d71dc146b46a0f1;p=linux-2.6 diff --git a/block/genhd.c b/block/genhd.c index 10b9ac46c2..e0ce23ac2e 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -190,7 +190,6 @@ void add_disk(struct gendisk *disk) disk->minors, NULL, exact_match, exact_lock, disk); register_disk(disk); blk_register_queue(disk); - blk_register_filter(disk); bdi = &disk->queue->backing_dev_info; bdi_register_dev(bdi, MKDEV(disk->major, disk->first_minor)); @@ -203,7 +202,6 @@ EXPORT_SYMBOL(del_gendisk); /* in partitions/check.c */ void unlink_gendisk(struct gendisk *disk) { - blk_unregister_filter(disk); sysfs_remove_link(&disk->dev.kobj, "bdi"); bdi_unregister(&disk->queue->backing_dev_info); blk_unregister_queue(disk); @@ -291,31 +289,51 @@ void __init printk_all_partitions(void) #ifdef CONFIG_PROC_FS /* iterator */ +static int find_start(struct device *dev, void *data) +{ + loff_t *k = data; + + if (dev->type != &disk_type) + return 0; + if (!*k) + return 1; + (*k)--; + return 0; +} + static void *part_start(struct seq_file *part, loff_t *pos) { - loff_t k = *pos; struct device *dev; + loff_t k = *pos; + + if (!k) + part->private = (void *)1LU; /* tell show to print header */ mutex_lock(&block_class_lock); - list_for_each_entry(dev, &block_class.devices, node) { - if (dev->type != &disk_type) - continue; - if (!k--) - return dev_to_disk(dev); + dev = class_find_device(&block_class, NULL, &k, find_start); + if (dev) { + put_device(dev); + return dev_to_disk(dev); } return NULL; } +static int find_next(struct device *dev, void *data) +{ + if (dev->type == &disk_type) + return 1; + return 0; +} + static void *part_next(struct seq_file *part, void *v, loff_t *pos) { struct gendisk *gp = v; struct device *dev; ++*pos; - list_for_each_entry(dev, &gp->dev.node, node) { - if (&dev->node == &block_class.devices) - return NULL; - if (dev->type == &disk_type) - return dev_to_disk(dev); + dev = class_find_device(&block_class, &gp->dev, NULL, find_next); + if (dev) { + put_device(dev); + return dev_to_disk(dev); } return NULL; } @@ -331,8 +349,16 @@ static int show_partition(struct seq_file *part, void *v) int n; char buf[BDEVNAME_SIZE]; - if (&sgp->dev.node == block_class.devices.next) + /* + * Print header if start told us to do. This is to preserve + * the original behavior of not printing header if no + * partition exists. This hackery will be removed later with + * class iteration clean up. + */ + if (part->private) { seq_puts(part, "major minor #blocks name\n\n"); + part->private = NULL; + } /* Don't show non-partitionable removeable devices or empty devices */ if (!get_capacity(sgp) || @@ -544,6 +570,7 @@ static struct device_type disk_type = { .release = disk_release, }; +#ifdef CONFIG_PROC_FS /* * aggregate disk stat collector. Uses the same stats that the sysfs * entries do, above, but makes them available through one seq_file. @@ -554,15 +581,14 @@ static struct device_type disk_type = { static void *diskstats_start(struct seq_file *part, loff_t *pos) { - loff_t k = *pos; struct device *dev; + loff_t k = *pos; mutex_lock(&block_class_lock); - list_for_each_entry(dev, &block_class.devices, node) { - if (dev->type != &disk_type) - continue; - if (!k--) - return dev_to_disk(dev); + dev = class_find_device(&block_class, NULL, &k, find_start); + if (dev) { + put_device(dev); + return dev_to_disk(dev); } return NULL; } @@ -573,11 +599,10 @@ static void *diskstats_next(struct seq_file *part, void *v, loff_t *pos) struct device *dev; ++*pos; - list_for_each_entry(dev, &gp->dev.node, node) { - if (&dev->node == &block_class.devices) - return NULL; - if (dev->type == &disk_type) - return dev_to_disk(dev); + dev = class_find_device(&block_class, &gp->dev, NULL, find_next); + if (dev) { + put_device(dev); + return dev_to_disk(dev); } return NULL; } @@ -653,6 +678,7 @@ const struct seq_operations diskstats_op = { .stop = diskstats_stop, .show = diskstats_show }; +#endif /* CONFIG_PROC_FS */ static void media_change_notify_thread(struct work_struct *work) { @@ -677,23 +703,39 @@ void genhd_media_change_notify(struct gendisk *disk) EXPORT_SYMBOL_GPL(genhd_media_change_notify); #endif /* 0 */ +struct find_block { + const char *name; + int part; +}; + +static int match_id(struct device *dev, void *data) +{ + struct find_block *find = data; + + if (dev->type != &disk_type) + return 0; + if (strcmp(dev->bus_id, find->name) == 0) { + struct gendisk *disk = dev_to_disk(dev); + if (find->part < disk->minors) + return 1; + } + return 0; +} + dev_t blk_lookup_devt(const char *name, int part) { struct device *dev; dev_t devt = MKDEV(0, 0); + struct find_block find; mutex_lock(&block_class_lock); - list_for_each_entry(dev, &block_class.devices, node) { - if (dev->type != &disk_type) - continue; - if (strcmp(dev->bus_id, name) == 0) { - struct gendisk *disk = dev_to_disk(dev); - - if (part < disk->minors) - devt = MKDEV(MAJOR(dev->devt), - MINOR(dev->devt) + part); - break; - } + find.name = name; + find.part = part; + dev = class_find_device(&block_class, NULL, &find, match_id); + if (dev) { + put_device(dev); + devt = MKDEV(MAJOR(dev->devt), + MINOR(dev->devt) + part); } mutex_unlock(&block_class_lock);