block: misc updates
[safe/jmp/linux-2.6] / block / genhd.c
index 7f71b2c..11038fb 100644 (file)
 #include <linux/buffer_head.h>
 #include <linux/mutex.h>
 
-struct kset block_subsys;
-static DEFINE_MUTEX(block_subsys_lock);
+#include "blk.h"
+
+static DEFINE_MUTEX(block_class_lock);
+#ifndef CONFIG_SYSFS_DEPRECATED
+struct kobject *block_depr;
+#endif
+
+static struct device_type disk_type;
 
 /*
  * Can be deleted altogether. Later.
@@ -37,19 +43,17 @@ static inline int major_to_index(int major)
 }
 
 #ifdef CONFIG_PROC_FS
-
 void blkdev_show(struct seq_file *f, off_t offset)
 {
        struct blk_major_name *dp;
 
        if (offset < BLKDEV_MAJOR_HASH_SIZE) {
-               mutex_lock(&block_subsys_lock);
+               mutex_lock(&block_class_lock);
                for (dp = major_names[offset]; dp; dp = dp->next)
                        seq_printf(f, "%3d %s\n", dp->major, dp->name);
-               mutex_unlock(&block_subsys_lock);
+               mutex_unlock(&block_class_lock);
        }
 }
-
 #endif /* CONFIG_PROC_FS */
 
 int register_blkdev(unsigned int major, const char *name)
@@ -57,7 +61,7 @@ int register_blkdev(unsigned int major, const char *name)
        struct blk_major_name **n, *p;
        int index, ret = 0;
 
-       mutex_lock(&block_subsys_lock);
+       mutex_lock(&block_class_lock);
 
        /* temporary */
        if (major == 0) {
@@ -102,35 +106,30 @@ int register_blkdev(unsigned int major, const char *name)
                kfree(p);
        }
 out:
-       mutex_unlock(&block_subsys_lock);
+       mutex_unlock(&block_class_lock);
        return ret;
 }
 
 EXPORT_SYMBOL(register_blkdev);
 
-/* todo: make void - error printk here */
-int unregister_blkdev(unsigned int major, const char *name)
+void unregister_blkdev(unsigned int major, const char *name)
 {
        struct blk_major_name **n;
        struct blk_major_name *p = NULL;
        int index = major_to_index(major);
-       int ret = 0;
 
-       mutex_lock(&block_subsys_lock);
+       mutex_lock(&block_class_lock);
        for (n = &major_names[index]; *n; n = &(*n)->next)
                if ((*n)->major == major)
                        break;
        if (!*n || strcmp((*n)->name, name)) {
                WARN_ON(1);
-               ret = -EINVAL;
        } else {
                p = *n;
                *n = p->next;
        }
-       mutex_unlock(&block_subsys_lock);
+       mutex_unlock(&block_class_lock);
        kfree(p);
-
-       return ret;
 }
 
 EXPORT_SYMBOL(unregister_blkdev);
@@ -142,29 +141,30 @@ static struct kobj_map *bdev_map;
  * range must be nonzero
  * The hash chain is sorted on range, so that subranges can override.
  */
-void blk_register_region(dev_t dev, unsigned long range, struct module *module,
+void blk_register_region(dev_t devt, unsigned long range, struct module *module,
                         struct kobject *(*probe)(dev_t, int *, void *),
                         int (*lock)(dev_t, void *), void *data)
 {
-       kobj_map(bdev_map, dev, range, module, probe, lock, data);
+       kobj_map(bdev_map, devt, range, module, probe, lock, data);
 }
 
 EXPORT_SYMBOL(blk_register_region);
 
-void blk_unregister_region(dev_t dev, unsigned long range)
+void blk_unregister_region(dev_t devt, unsigned long range)
 {
-       kobj_unmap(bdev_map, dev, range);
+       kobj_unmap(bdev_map, devt, range);
 }
 
 EXPORT_SYMBOL(blk_unregister_region);
 
-static struct kobject *exact_match(dev_t dev, int *part, void *data)
+static struct kobject *exact_match(dev_t devt, int *part, void *data)
 {
        struct gendisk *p = data;
-       return &p->kobj;
+
+       return &p->dev.kobj;
 }
 
-static int exact_lock(dev_t dev, void *data)
+static int exact_lock(dev_t devt, void *data)
 {
        struct gendisk *p = data;
 
@@ -182,11 +182,19 @@ static int exact_lock(dev_t dev, void *data)
  */
 void add_disk(struct gendisk *disk)
 {
+       struct backing_dev_info *bdi;
+       int retval;
+
        disk->flags |= GENHD_FL_UP;
        blk_register_region(MKDEV(disk->major, disk->first_minor),
                            disk->minors, NULL, exact_match, exact_lock, disk);
        register_disk(disk);
        blk_register_queue(disk);
+
+       bdi = &disk->queue->backing_dev_info;
+       bdi_register_dev(bdi, MKDEV(disk->major, disk->first_minor));
+       retval = sysfs_create_link(&disk->dev.kobj, &bdi->dev->kobj, "bdi");
+       WARN_ON(retval);
 }
 
 EXPORT_SYMBOL(add_disk);
@@ -194,24 +202,27 @@ EXPORT_SYMBOL(del_gendisk);       /* in partitions/check.c */
 
 void unlink_gendisk(struct gendisk *disk)
 {
+       sysfs_remove_link(&disk->dev.kobj, "bdi");
+       bdi_unregister(&disk->queue->backing_dev_info);
        blk_unregister_queue(disk);
        blk_unregister_region(MKDEV(disk->major, disk->first_minor),
                              disk->minors);
 }
 
-#define to_disk(obj) container_of(obj,struct gendisk,kobj)
-
 /**
  * get_gendisk - get partitioning information for a given device
- * @dev: device to get partitioning information for
+ * @devt: device to get partitioning information for
+ * @part: returned partition index
  *
  * This function gets the structure containing partitioning
- * information for the given device @dev.
+ * information for the given device @devt.
  */
-struct gendisk *get_gendisk(dev_t dev, int *part)
+struct gendisk *get_gendisk(dev_t devt, int *part)
 {
-       struct kobject *kobj = kobj_lookup(bdev_map, dev, part);
-       return  kobj ? to_disk(kobj) : NULL;
+       struct kobject *kobj = kobj_lookup(bdev_map, devt, part);
+       struct device *dev = kobj_to_dev(kobj);
+
+       return  kobj ? dev_to_disk(dev) : NULL;
 }
 
 /*
@@ -221,77 +232,108 @@ struct gendisk *get_gendisk(dev_t dev, int *part)
  */
 void __init printk_all_partitions(void)
 {
-       int n;
-       struct gendisk *sgp;
+       struct class_dev_iter iter;
+       struct device *dev;
 
-       mutex_lock(&block_subsys_lock);
-       /* For each block device... */
-       list_for_each_entry(sgp, &block_subsys.list, kobj.entry) {
+       class_dev_iter_init(&iter, &block_class, NULL, &disk_type);
+       while ((dev = class_dev_iter_next(&iter))) {
+               struct gendisk *disk = dev_to_disk(dev);
                char buf[BDEVNAME_SIZE];
+               int n;
+
                /*
-                * Don't show empty devices or things that have been surpressed
+                * Don't show empty devices or things that have been
+                * surpressed
                 */
-               if (get_capacity(sgp) == 0 ||
-                   (sgp->flags & GENHD_FL_SUPPRESS_PARTITION_INFO))
+               if (get_capacity(disk) == 0 ||
+                   (disk->flags & GENHD_FL_SUPPRESS_PARTITION_INFO))
                        continue;
 
                /*
-                * Note, unlike /proc/partitions, I am showing the numbers in
-                * hex - the same format as the root= option takes.
+                * Note, unlike /proc/partitions, I am showing the
+                * numbers in hex - the same format as the root=
+                * option takes.
                 */
                printk("%02x%02x %10llu %s",
-                       sgp->major, sgp->first_minor,
-                       (unsigned long long)get_capacity(sgp) >> 1,
-                       disk_name(sgp, 0, buf));
-               if (sgp->driverfs_dev != NULL &&
-                   sgp->driverfs_dev->driver != NULL)
+                      disk->major, disk->first_minor,
+                      (unsigned long long)get_capacity(disk) >> 1,
+                      disk_name(disk, 0, buf));
+               if (disk->driverfs_dev != NULL &&
+                   disk->driverfs_dev->driver != NULL)
                        printk(" driver: %s\n",
-                               sgp->driverfs_dev->driver->name);
+                              disk->driverfs_dev->driver->name);
                else
                        printk(" (driver?)\n");
 
                /* now show the partitions */
-               for (n = 0; n < sgp->minors - 1; ++n) {
-                       if (sgp->part[n] == NULL)
+               for (n = 0; n < disk->minors - 1; ++n) {
+                       if (disk->part[n] == NULL)
                                continue;
-                       if (sgp->part[n]->nr_sects == 0)
+                       if (disk->part[n]->nr_sects == 0)
                                continue;
                        printk("  %02x%02x %10llu %s\n",
-                               sgp->major, n + 1 + sgp->first_minor,
-                               (unsigned long long)sgp->part[n]->nr_sects >> 1,
-                               disk_name(sgp, n + 1, buf));
-               } /* partition subloop */
-       } /* Block device loop */
-
-       mutex_unlock(&block_subsys_lock);
-       return;
+                              disk->major, n + 1 + disk->first_minor,
+                              (unsigned long long)disk->part[n]->nr_sects >> 1,
+                              disk_name(disk, n + 1, buf));
+               }
+       }
+       class_dev_iter_exit(&iter);
 }
 
 #ifdef CONFIG_PROC_FS
 /* iterator */
-static void *part_start(struct seq_file *part, loff_t *pos)
+static void *disk_seqf_start(struct seq_file *seqf, loff_t *pos)
+{
+       loff_t skip = *pos;
+       struct class_dev_iter *iter;
+       struct device *dev;
+
+       iter = kmalloc(GFP_KERNEL, sizeof(*iter));
+       if (!iter)
+               return ERR_PTR(-ENOMEM);
+
+       seqf->private = iter;
+       class_dev_iter_init(iter, &block_class, NULL, &disk_type);
+       do {
+               dev = class_dev_iter_next(iter);
+               if (!dev)
+                       return NULL;
+       } while (skip--);
+
+       return dev_to_disk(dev);
+}
+
+static void *disk_seqf_next(struct seq_file *seqf, void *v, loff_t *pos)
 {
-       struct list_head *p;
-       loff_t l = *pos;
+       struct device *dev;
+
+       (*pos)++;
+       dev = class_dev_iter_next(seqf->private);
+       if (dev)
+               return dev_to_disk(dev);
 
-       mutex_lock(&block_subsys_lock);
-       list_for_each(p, &block_subsys.list)
-               if (!l--)
-                       return list_entry(p, struct gendisk, kobj.entry);
        return NULL;
 }
 
-static void *part_next(struct seq_file *part, void *v, loff_t *pos)
+static void disk_seqf_stop(struct seq_file *seqf, void *v)
 {
-       struct list_head *p = ((struct gendisk *)v)->kobj.entry.next;
-       ++*pos;
-       return p==&block_subsys.list ? NULL :
-               list_entry(p, struct gendisk, kobj.entry);
+       struct class_dev_iter *iter = seqf->private;
+
+       /* stop is called even after start failed :-( */
+       if (iter) {
+               class_dev_iter_exit(iter);
+               kfree(iter);
+       }
 }
 
-static void part_stop(struct seq_file *part, void *v)
+static void *show_partition_start(struct seq_file *seqf, loff_t *pos)
 {
-       mutex_unlock(&block_subsys_lock);
+       static void *p;
+
+       p = disk_seqf_start(seqf, pos);
+       if (!IS_ERR(p) && p)
+               seq_puts(seqf, "major minor  #blocks  name\n\n");
+       return p;
 }
 
 static int show_partition(struct seq_file *part, void *v)
@@ -300,8 +342,16 @@ static int show_partition(struct seq_file *part, void *v)
        int n;
        char buf[BDEVNAME_SIZE];
 
-       if (&sgp->kobj.entry == block_subsys.list.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) ||
@@ -329,111 +379,93 @@ static int show_partition(struct seq_file *part, void *v)
        return 0;
 }
 
-struct seq_operations partitions_op = {
-       .start =part_start,
-       .next = part_next,
-       .stop = part_stop,
-       .show = show_partition
+const struct seq_operations partitions_op = {
+       .start  = show_partition_start,
+       .next   = disk_seqf_next,
+       .stop   = disk_seqf_stop,
+       .show   = show_partition
 };
 #endif
 
 
-extern int blk_dev_init(void);
-
-static struct kobject *base_probe(dev_t dev, int *part, void *data)
+static struct kobject *base_probe(dev_t devt, int *part, void *data)
 {
-       if (request_module("block-major-%d-%d", MAJOR(dev), MINOR(dev)) > 0)
+       if (request_module("block-major-%d-%d", MAJOR(devt), MINOR(devt)) > 0)
                /* Make old-style 2.4 aliases work */
-               request_module("block-major-%d", MAJOR(dev));
+               request_module("block-major-%d", MAJOR(devt));
        return NULL;
 }
 
 static int __init genhd_device_init(void)
 {
-       int err;
+       int error;
 
-       bdev_map = kobj_map_init(base_probe, &block_subsys_lock);
+       block_class.dev_kobj = sysfs_dev_block_kobj;
+       error = class_register(&block_class);
+       if (unlikely(error))
+               return error;
+       bdev_map = kobj_map_init(base_probe, &block_class_lock);
        blk_dev_init();
-       err = subsystem_register(&block_subsys);
-       if (err < 0)
-               printk(KERN_WARNING "%s: subsystem_register error: %d\n",
-                       __FUNCTION__, err);
-       return err;
+
+#ifndef CONFIG_SYSFS_DEPRECATED
+       /* create top-level block dir */
+       block_depr = kobject_create_and_add("block", NULL);
+#endif
+       return 0;
 }
 
 subsys_initcall(genhd_device_init);
 
-
-
-/*
- * kobject & sysfs bindings for block devices
- */
-static ssize_t disk_attr_show(struct kobject *kobj, struct attribute *attr,
-                             char *page)
+static ssize_t disk_range_show(struct device *dev,
+                              struct device_attribute *attr, char *buf)
 {
-       struct gendisk *disk = to_disk(kobj);
-       struct disk_attribute *disk_attr =
-               container_of(attr,struct disk_attribute,attr);
-       ssize_t ret = -EIO;
+       struct gendisk *disk = dev_to_disk(dev);
 
-       if (disk_attr->show)
-               ret = disk_attr->show(disk,page);
-       return ret;
+       return sprintf(buf, "%d\n", disk->minors);
 }
 
-static ssize_t disk_attr_store(struct kobject * kobj, struct attribute * attr,
-                              const char *page, size_t count)
+static ssize_t disk_removable_show(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
 {
-       struct gendisk *disk = to_disk(kobj);
-       struct disk_attribute *disk_attr =
-               container_of(attr,struct disk_attribute,attr);
-       ssize_t ret = 0;
+       struct gendisk *disk = dev_to_disk(dev);
 
-       if (disk_attr->store)
-               ret = disk_attr->store(disk, page, count);
-       return ret;
+       return sprintf(buf, "%d\n",
+                      (disk->flags & GENHD_FL_REMOVABLE ? 1 : 0));
 }
 
-static struct sysfs_ops disk_sysfs_ops = {
-       .show   = &disk_attr_show,
-       .store  = &disk_attr_store,
-};
-
-static ssize_t disk_uevent_store(struct gendisk * disk,
-                                const char *buf, size_t count)
-{
-       kobject_uevent(&disk->kobj, KOBJ_ADD);
-       return count;
-}
-static ssize_t disk_dev_read(struct gendisk * disk, char *page)
-{
-       dev_t base = MKDEV(disk->major, disk->first_minor); 
-       return print_dev_t(page, base);
-}
-static ssize_t disk_range_read(struct gendisk * disk, char *page)
-{
-       return sprintf(page, "%d\n", disk->minors);
-}
-static ssize_t disk_removable_read(struct gendisk * disk, char *page)
+static ssize_t disk_ro_show(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
 {
-       return sprintf(page, "%d\n",
-                      (disk->flags & GENHD_FL_REMOVABLE ? 1 : 0));
+       struct gendisk *disk = dev_to_disk(dev);
 
+       return sprintf(buf, "%d\n", disk->policy ? 1 : 0);
 }
-static ssize_t disk_size_read(struct gendisk * disk, char *page)
+
+static ssize_t disk_size_show(struct device *dev,
+                             struct device_attribute *attr, char *buf)
 {
-       return sprintf(page, "%llu\n", (unsigned long long)get_capacity(disk));
+       struct gendisk *disk = dev_to_disk(dev);
+
+       return sprintf(buf, "%llu\n", (unsigned long long)get_capacity(disk));
 }
-static ssize_t disk_capability_read(struct gendisk *disk, char *page)
+
+static ssize_t disk_capability_show(struct device *dev,
+                                   struct device_attribute *attr, char *buf)
 {
-       return sprintf(page, "%x\n", disk->flags);
+       struct gendisk *disk = dev_to_disk(dev);
+
+       return sprintf(buf, "%x\n", disk->flags);
 }
-static ssize_t disk_stats_read(struct gendisk * disk, char *page)
+
+static ssize_t disk_stat_show(struct device *dev,
+                             struct device_attribute *attr, char *buf)
 {
+       struct gendisk *disk = dev_to_disk(dev);
+
        preempt_disable();
        disk_round_stats(disk);
        preempt_enable();
-       return sprintf(page,
+       return sprintf(buf,
                "%8lu %8lu %8llu %8u "
                "%8lu %8lu %8llu %8u "
                "%8u %8u %8u"
@@ -450,40 +482,21 @@ static ssize_t disk_stats_read(struct gendisk * disk, char *page)
                jiffies_to_msecs(disk_stat_read(disk, io_ticks)),
                jiffies_to_msecs(disk_stat_read(disk, time_in_queue)));
 }
-static struct disk_attribute disk_attr_uevent = {
-       .attr = {.name = "uevent", .mode = S_IWUSR },
-       .store  = disk_uevent_store
-};
-static struct disk_attribute disk_attr_dev = {
-       .attr = {.name = "dev", .mode = S_IRUGO },
-       .show   = disk_dev_read
-};
-static struct disk_attribute disk_attr_range = {
-       .attr = {.name = "range", .mode = S_IRUGO },
-       .show   = disk_range_read
-};
-static struct disk_attribute disk_attr_removable = {
-       .attr = {.name = "removable", .mode = S_IRUGO },
-       .show   = disk_removable_read
-};
-static struct disk_attribute disk_attr_size = {
-       .attr = {.name = "size", .mode = S_IRUGO },
-       .show   = disk_size_read
-};
-static struct disk_attribute disk_attr_capability = {
-       .attr = {.name = "capability", .mode = S_IRUGO },
-       .show   = disk_capability_read
-};
-static struct disk_attribute disk_attr_stat = {
-       .attr = {.name = "stat", .mode = S_IRUGO },
-       .show   = disk_stats_read
-};
 
 #ifdef CONFIG_FAIL_MAKE_REQUEST
+static ssize_t disk_fail_show(struct device *dev,
+                             struct device_attribute *attr, char *buf)
+{
+       struct gendisk *disk = dev_to_disk(dev);
+
+       return sprintf(buf, "%d\n", disk->flags & GENHD_FL_FAIL ? 1 : 0);
+}
 
-static ssize_t disk_fail_store(struct gendisk * disk,
+static ssize_t disk_fail_store(struct device *dev,
+                              struct device_attribute *attr,
                               const char *buf, size_t count)
 {
+       struct gendisk *disk = dev_to_disk(dev);
        int i;
 
        if (count > 0 && sscanf(buf, "%d", &i) > 0) {
@@ -495,165 +508,70 @@ static ssize_t disk_fail_store(struct gendisk * disk,
 
        return count;
 }
-static ssize_t disk_fail_read(struct gendisk * disk, char *page)
-{
-       return sprintf(page, "%d\n", disk->flags & GENHD_FL_FAIL ? 1 : 0);
-}
-static struct disk_attribute disk_attr_fail = {
-       .attr = {.name = "make-it-fail", .mode = S_IRUGO | S_IWUSR },
-       .store  = disk_fail_store,
-       .show   = disk_fail_read
-};
 
 #endif
 
-static struct attribute * default_attrs[] = {
-       &disk_attr_uevent.attr,
-       &disk_attr_dev.attr,
-       &disk_attr_range.attr,
-       &disk_attr_removable.attr,
-       &disk_attr_size.attr,
-       &disk_attr_stat.attr,
-       &disk_attr_capability.attr,
+static DEVICE_ATTR(range, S_IRUGO, disk_range_show, NULL);
+static DEVICE_ATTR(removable, S_IRUGO, disk_removable_show, NULL);
+static DEVICE_ATTR(ro, S_IRUGO, disk_ro_show, NULL);
+static DEVICE_ATTR(size, S_IRUGO, disk_size_show, NULL);
+static DEVICE_ATTR(capability, S_IRUGO, disk_capability_show, NULL);
+static DEVICE_ATTR(stat, S_IRUGO, disk_stat_show, NULL);
+#ifdef CONFIG_FAIL_MAKE_REQUEST
+static struct device_attribute dev_attr_fail =
+       __ATTR(make-it-fail, S_IRUGO|S_IWUSR, disk_fail_show, disk_fail_store);
+#endif
+
+static struct attribute *disk_attrs[] = {
+       &dev_attr_range.attr,
+       &dev_attr_removable.attr,
+       &dev_attr_ro.attr,
+       &dev_attr_size.attr,
+       &dev_attr_capability.attr,
+       &dev_attr_stat.attr,
 #ifdef CONFIG_FAIL_MAKE_REQUEST
-       &disk_attr_fail.attr,
+       &dev_attr_fail.attr,
 #endif
-       NULL,
+       NULL
+};
+
+static struct attribute_group disk_attr_group = {
+       .attrs = disk_attrs,
 };
 
-static void disk_release(struct kobject * kobj)
+static struct attribute_group *disk_attr_groups[] = {
+       &disk_attr_group,
+       NULL
+};
+
+static void disk_release(struct device *dev)
 {
-       struct gendisk *disk = to_disk(kobj);
+       struct gendisk *disk = dev_to_disk(dev);
+
        kfree(disk->random);
        kfree(disk->part);
        free_disk_stats(disk);
        kfree(disk);
 }
-
-static struct kobj_type ktype_block = {
-       .release        = disk_release,
-       .sysfs_ops      = &disk_sysfs_ops,
-       .default_attrs  = default_attrs,
+struct class block_class = {
+       .name           = "block",
 };
 
-extern struct kobj_type ktype_part;
-
-static int block_uevent_filter(struct kset *kset, struct kobject *kobj)
-{
-       struct kobj_type *ktype = get_ktype(kobj);
-
-       return ((ktype == &ktype_block) || (ktype == &ktype_part));
-}
-
-static int block_uevent(struct kset *kset, struct kobject *kobj, char **envp,
-                        int num_envp, char *buffer, int buffer_size)
-{
-       struct kobj_type *ktype = get_ktype(kobj);
-       struct device *physdev;
-       struct gendisk *disk;
-       struct hd_struct *part;
-       int length = 0;
-       int i = 0;
-
-       if (ktype == &ktype_block) {
-               disk = container_of(kobj, struct gendisk, kobj);
-               add_uevent_var(envp, num_envp, &i, buffer, buffer_size,
-                              &length, "MINOR=%u", disk->first_minor);
-       } else if (ktype == &ktype_part) {
-               disk = container_of(kobj->parent, struct gendisk, kobj);
-               part = container_of(kobj, struct hd_struct, kobj);
-               add_uevent_var(envp, num_envp, &i, buffer, buffer_size,
-                              &length, "MINOR=%u",
-                              disk->first_minor + part->partno);
-       } else
-               return 0;
-
-       add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &length,
-                      "MAJOR=%u", disk->major);
-
-       /* add physical device, backing this device  */
-       physdev = disk->driverfs_dev;
-       if (physdev) {
-               char *path = kobject_get_path(&physdev->kobj, GFP_KERNEL);
-
-               add_uevent_var(envp, num_envp, &i, buffer, buffer_size,
-                              &length, "PHYSDEVPATH=%s", path);
-               kfree(path);
-
-               if (physdev->bus)
-                       add_uevent_var(envp, num_envp, &i,
-                                      buffer, buffer_size, &length,
-                                      "PHYSDEVBUS=%s",
-                                      physdev->bus->name);
-
-               if (physdev->driver)
-                       add_uevent_var(envp, num_envp, &i,
-                                      buffer, buffer_size, &length,
-                                      "PHYSDEVDRIVER=%s",
-                                      physdev->driver->name);
-       }
-
-       /* terminate, set to next free slot, shrink available space */
-       envp[i] = NULL;
-       envp = &envp[i];
-       num_envp -= i;
-       buffer = &buffer[length];
-       buffer_size -= length;
-
-       return 0;
-}
-
-static struct kset_uevent_ops block_uevent_ops = {
-       .filter         = block_uevent_filter,
-       .uevent         = block_uevent,
+static struct device_type disk_type = {
+       .name           = "disk",
+       .groups         = disk_attr_groups,
+       .release        = disk_release,
 };
 
-decl_subsys(block, &ktype_block, &block_uevent_ops);
-
-/*
- * aggregate disk stat collector.  Uses the same stats that the sysfs
- * entries do, above, but makes them available through one seq_file.
- * Watching a few disks may be efficient through sysfs, but watching
- * all of them will be more efficient through this interface.
- *
- * The output looks suspiciously like /proc/partitions with a bunch of
- * extra fields.
- */
-
-/* iterator */
-static void *diskstats_start(struct seq_file *part, loff_t *pos)
-{
-       loff_t k = *pos;
-       struct list_head *p;
-
-       mutex_lock(&block_subsys_lock);
-       list_for_each(p, &block_subsys.list)
-               if (!k--)
-                       return list_entry(p, struct gendisk, kobj.entry);
-       return NULL;
-}
-
-static void *diskstats_next(struct seq_file *part, void *v, loff_t *pos)
-{
-       struct list_head *p = ((struct gendisk *)v)->kobj.entry.next;
-       ++*pos;
-       return p==&block_subsys.list ? NULL :
-               list_entry(p, struct gendisk, kobj.entry);
-}
-
-static void diskstats_stop(struct seq_file *part, void *v)
-{
-       mutex_unlock(&block_subsys_lock);
-}
-
+#ifdef CONFIG_PROC_FS
 static int diskstats_show(struct seq_file *s, void *v)
 {
        struct gendisk *gp = v;
        char buf[BDEVNAME_SIZE];
-       int n = 0;
+       int n;
 
        /*
-       if (&sgp->kobj.entry == block_subsys.kset.list.next)
+       if (&gp->dev.kobj.entry == block_class.devices.next)
                seq_puts(s,     "major minor name"
                                "     rio rmerge rsect ruse wio wmerge "
                                "wsect wuse running use aveq"
@@ -664,7 +582,7 @@ static int diskstats_show(struct seq_file *s, void *v)
        disk_round_stats(gp);
        preempt_enable();
        seq_printf(s, "%4d %4d %s %lu %lu %llu %u %lu %lu %llu %u %u %u %u\n",
-               gp->major, n + gp->first_minor, disk_name(gp, n, buf),
+               gp->major, gp->first_minor, disk_name(gp, 0, buf),
                disk_stat_read(gp, ios[0]), disk_stat_read(gp, merges[0]),
                (unsigned long long)disk_stat_read(gp, sectors[0]),
                jiffies_to_msecs(disk_stat_read(gp, ticks[0])),
@@ -679,23 +597,40 @@ static int diskstats_show(struct seq_file *s, void *v)
        for (n = 0; n < gp->minors - 1; n++) {
                struct hd_struct *hd = gp->part[n];
 
-               if (hd && hd->nr_sects)
-                       seq_printf(s, "%4d %4d %s %u %u %u %u\n",
-                               gp->major, n + gp->first_minor + 1,
-                               disk_name(gp, n + 1, buf),
-                               hd->ios[0], hd->sectors[0],
-                               hd->ios[1], hd->sectors[1]);
+               if (!hd || !hd->nr_sects)
+                       continue;
+
+               preempt_disable();
+               part_round_stats(hd);
+               preempt_enable();
+               seq_printf(s, "%4d %4d %s %lu %lu %llu "
+                          "%u %lu %lu %llu %u %u %u %u\n",
+                          gp->major, n + gp->first_minor + 1,
+                          disk_name(gp, n + 1, buf),
+                          part_stat_read(hd, ios[0]),
+                          part_stat_read(hd, merges[0]),
+                          (unsigned long long)part_stat_read(hd, sectors[0]),
+                          jiffies_to_msecs(part_stat_read(hd, ticks[0])),
+                          part_stat_read(hd, ios[1]),
+                          part_stat_read(hd, merges[1]),
+                          (unsigned long long)part_stat_read(hd, sectors[1]),
+                          jiffies_to_msecs(part_stat_read(hd, ticks[1])),
+                          hd->in_flight,
+                          jiffies_to_msecs(part_stat_read(hd, io_ticks)),
+                          jiffies_to_msecs(part_stat_read(hd, time_in_queue))
+                       );
        }
  
        return 0;
 }
 
-struct seq_operations diskstats_op = {
-       .start  = diskstats_start,
-       .next   = diskstats_next,
-       .stop   = diskstats_stop,
+const struct seq_operations diskstats_op = {
+       .start  = disk_seqf_start,
+       .next   = disk_seqf_next,
+       .stop   = disk_seqf_stop,
        .show   = diskstats_show
 };
+#endif /* CONFIG_PROC_FS */
 
 static void media_change_notify_thread(struct work_struct *work)
 {
@@ -707,16 +642,39 @@ static void media_change_notify_thread(struct work_struct *work)
         * set enviroment vars to indicate which event this is for
         * so that user space will know to go check the media status.
         */
-       kobject_uevent_env(&gd->kobj, KOBJ_CHANGE, envp);
+       kobject_uevent_env(&gd->dev.kobj, KOBJ_CHANGE, envp);
        put_device(gd->driverfs_dev);
 }
 
+#if 0
 void genhd_media_change_notify(struct gendisk *disk)
 {
        get_device(disk->driverfs_dev);
        schedule_work(&disk->async_notify);
 }
 EXPORT_SYMBOL_GPL(genhd_media_change_notify);
+#endif  /*  0  */
+
+dev_t blk_lookup_devt(const char *name, int part)
+{
+       dev_t devt = MKDEV(0, 0);
+       struct class_dev_iter iter;
+       struct device *dev;
+
+       class_dev_iter_init(&iter, &block_class, NULL, &disk_type);
+       while ((dev = class_dev_iter_next(&iter))) {
+               struct gendisk *disk = dev_to_disk(dev);
+
+               if (!strcmp(dev->bus_id, name) && part < disk->minors) {
+                       devt = MKDEV(MAJOR(dev->devt),
+                                    MINOR(dev->devt) + part);
+                       break;
+               }
+       }
+       class_dev_iter_exit(&iter);
+       return devt;
+}
+EXPORT_SYMBOL(blk_lookup_devt);
 
 struct gendisk *alloc_disk(int minors)
 {
@@ -739,14 +697,16 @@ struct gendisk *alloc_disk_node(int minors, int node_id)
                        disk->part = kmalloc_node(size,
                                GFP_KERNEL | __GFP_ZERO, node_id);
                        if (!disk->part) {
+                               free_disk_stats(disk);
                                kfree(disk);
                                return NULL;
                        }
                }
                disk->minors = minors;
-               kobj_set_kset_s(disk,block_subsys);
-               kobject_init(&disk->kobj);
                rand_initialize_disk(disk);
+               disk->dev.class = &block_class;
+               disk->dev.type = &disk_type;
+               device_initialize(&disk->dev);
                INIT_WORK(&disk->async_notify,
                        media_change_notify_thread);
        }
@@ -766,7 +726,7 @@ struct kobject *get_disk(struct gendisk *disk)
        owner = disk->fops->owner;
        if (owner && !try_module_get(owner))
                return NULL;
-       kobj = kobject_get(&disk->kobj);
+       kobj = kobject_get(&disk->dev.kobj);
        if (kobj == NULL) {
                module_put(owner);
                return NULL;
@@ -780,7 +740,7 @@ EXPORT_SYMBOL(get_disk);
 void put_disk(struct gendisk *disk)
 {
        if (disk)
-               kobject_put(&disk->kobj);
+               kobject_put(&disk->dev.kobj);
 }
 
 EXPORT_SYMBOL(put_disk);