Merge branch 'for-2.6.37/core' of git://git.kernel.dk/linux-2.6-block
[linux-2.6.git] / block / genhd.c
index a9ec910..8313834 100644 (file)
@@ -98,7 +98,7 @@ void disk_part_iter_init(struct disk_part_iter *piter, struct gendisk *disk,
 
        if (flags & DISK_PITER_REVERSE)
                piter->idx = ptbl->len - 1;
-       else if (flags & DISK_PITER_INCL_PART0)
+       else if (flags & (DISK_PITER_INCL_PART0 | DISK_PITER_INCL_EMPTY_PART0))
                piter->idx = 0;
        else
                piter->idx = 1;
@@ -134,7 +134,8 @@ struct hd_struct *disk_part_iter_next(struct disk_part_iter *piter)
        /* determine iteration parameters */
        if (piter->flags & DISK_PITER_REVERSE) {
                inc = -1;
-               if (piter->flags & DISK_PITER_INCL_PART0)
+               if (piter->flags & (DISK_PITER_INCL_PART0 |
+                                   DISK_PITER_INCL_EMPTY_PART0))
                        end = -1;
                else
                        end = 0;
@@ -150,7 +151,10 @@ struct hd_struct *disk_part_iter_next(struct disk_part_iter *piter)
                part = rcu_dereference(ptbl->part[piter->idx]);
                if (!part)
                        continue;
-               if (!(piter->flags & DISK_PITER_INCL_EMPTY) && !part->nr_sects)
+               if (!part->nr_sects &&
+                   !(piter->flags & DISK_PITER_INCL_EMPTY) &&
+                   !(piter->flags & DISK_PITER_INCL_EMPTY_PART0 &&
+                     piter->idx == 0))
                        continue;
 
                get_device(part_to_dev(part));
@@ -537,13 +541,15 @@ void add_disk(struct gendisk *disk)
        disk->major = MAJOR(devt);
        disk->first_minor = MINOR(devt);
 
+       /* Register BDI before referencing it from bdev */ 
+       bdi = &disk->queue->backing_dev_info;
+       bdi_register_dev(bdi, disk_devt(disk));
+
        blk_register_region(disk_devt(disk), 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, disk_devt(disk));
        retval = sysfs_create_link(&disk_to_dev(disk)->kobj, &bdi->dev->kobj,
                                   "bdi");
        WARN_ON(retval);
@@ -592,6 +598,7 @@ struct gendisk *get_gendisk(dev_t devt, int *partno)
 
        return disk;
 }
+EXPORT_SYMBOL(get_gendisk);
 
 /**
  * bdget_disk - do bdget() by gendisk and partition number
@@ -637,6 +644,7 @@ void __init printk_all_partitions(void)
                struct hd_struct *part;
                char name_buf[BDEVNAME_SIZE];
                char devt_buf[BDEVT_SIZE];
+               u8 uuid[PARTITION_META_INFO_UUIDLTH * 2 + 1];
 
                /*
                 * Don't show empty devices or things that have been
@@ -655,10 +663,14 @@ void __init printk_all_partitions(void)
                while ((part = disk_part_iter_next(&piter))) {
                        bool is_part0 = part == &disk->part0;
 
-                       printk("%s%s %10llu %s", is_part0 ? "" : "  ",
+                       uuid[0] = 0;
+                       if (part->info)
+                               part_unpack_uuid(part->info->uuid, uuid);
+
+                       printk("%s%s %10llu %s %s", is_part0 ? "" : "  ",
                               bdevt_str(part_devt(part), devt_buf),
                               (unsigned long long)part->nr_sects >> 1,
-                              disk_name(disk, part->partno, name_buf));
+                              disk_name(disk, part->partno, name_buf), uuid);
                        if (is_part0) {
                                if (disk->driverfs_dev != NULL &&
                                    disk->driverfs_dev->driver != NULL)
@@ -848,13 +860,35 @@ static ssize_t disk_capability_show(struct device *dev,
        return sprintf(buf, "%x\n", disk->flags);
 }
 
+static ssize_t disk_alignment_offset_show(struct device *dev,
+                                         struct device_attribute *attr,
+                                         char *buf)
+{
+       struct gendisk *disk = dev_to_disk(dev);
+
+       return sprintf(buf, "%d\n", queue_alignment_offset(disk->queue));
+}
+
+static ssize_t disk_discard_alignment_show(struct device *dev,
+                                          struct device_attribute *attr,
+                                          char *buf)
+{
+       struct gendisk *disk = dev_to_disk(dev);
+
+       return sprintf(buf, "%d\n", queue_discard_alignment(disk->queue));
+}
+
 static DEVICE_ATTR(range, S_IRUGO, disk_range_show, NULL);
 static DEVICE_ATTR(ext_range, S_IRUGO, disk_ext_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, part_size_show, NULL);
+static DEVICE_ATTR(alignment_offset, S_IRUGO, disk_alignment_offset_show, NULL);
+static DEVICE_ATTR(discard_alignment, S_IRUGO, disk_discard_alignment_show,
+                  NULL);
 static DEVICE_ATTR(capability, S_IRUGO, disk_capability_show, NULL);
 static DEVICE_ATTR(stat, S_IRUGO, part_stat_show, NULL);
+static DEVICE_ATTR(inflight, S_IRUGO, part_inflight_show, NULL);
 #ifdef CONFIG_FAIL_MAKE_REQUEST
 static struct device_attribute dev_attr_fail =
        __ATTR(make-it-fail, S_IRUGO|S_IWUSR, part_fail_show, part_fail_store);
@@ -871,8 +905,11 @@ static struct attribute *disk_attrs[] = {
        &dev_attr_removable.attr,
        &dev_attr_ro.attr,
        &dev_attr_size.attr,
+       &dev_attr_alignment_offset.attr,
+       &dev_attr_discard_alignment.attr,
        &dev_attr_capability.attr,
        &dev_attr_stat.attr,
+       &dev_attr_inflight.attr,
 #ifdef CONFIG_FAIL_MAKE_REQUEST
        &dev_attr_fail.attr,
 #endif
@@ -886,7 +923,7 @@ static struct attribute_group disk_attr_group = {
        .attrs = disk_attrs,
 };
 
-static struct attribute_group *disk_attr_groups[] = {
+static const struct attribute_group *disk_attr_groups[] = {
        &disk_attr_group,
        NULL
 };
@@ -895,8 +932,15 @@ static void disk_free_ptbl_rcu_cb(struct rcu_head *head)
 {
        struct disk_part_tbl *ptbl =
                container_of(head, struct disk_part_tbl, rcu_head);
+       struct gendisk *disk = ptbl->disk;
+       struct request_queue *q = disk->queue;
+       unsigned long flags;
 
        kfree(ptbl);
+
+       spin_lock_irqsave(q->queue_lock, flags);
+       elv_quiesce_end(q);
+       spin_unlock_irqrestore(q->queue_lock, flags);
 }
 
 /**
@@ -914,11 +958,17 @@ static void disk_replace_part_tbl(struct gendisk *disk,
                                  struct disk_part_tbl *new_ptbl)
 {
        struct disk_part_tbl *old_ptbl = disk->part_tbl;
+       struct request_queue *q = disk->queue;
 
        rcu_assign_pointer(disk->part_tbl, new_ptbl);
 
        if (old_ptbl) {
                rcu_assign_pointer(old_ptbl->last_lookup, NULL);
+
+               spin_lock_irq(q->queue_lock);
+               elv_quiesce_start(q);
+               spin_unlock_irq(q->queue_lock);
+
                call_rcu(&old_ptbl->rcu_head, disk_free_ptbl_rcu_cb);
        }
 }
@@ -958,8 +1008,8 @@ int disk_expand_part_tbl(struct gendisk *disk, int partno)
        if (!new_ptbl)
                return -ENOMEM;
 
-       INIT_RCU_HEAD(&new_ptbl->rcu_head);
        new_ptbl->len = target;
+       new_ptbl->disk = disk;
 
        for (i = 0; i < len; i++)
                rcu_assign_pointer(new_ptbl->part[i], old_ptbl->part[i]);
@@ -975,16 +1025,27 @@ static void disk_release(struct device *dev)
        kfree(disk->random);
        disk_replace_part_tbl(disk, NULL);
        free_part_stats(&disk->part0);
+       free_part_info(&disk->part0);
        kfree(disk);
 }
 struct class block_class = {
        .name           = "block",
 };
 
+static char *block_devnode(struct device *dev, mode_t *mode)
+{
+       struct gendisk *disk = dev_to_disk(dev);
+
+       if (disk->devnode)
+               return disk->devnode(disk, mode);
+       return NULL;
+}
+
 static struct device_type disk_type = {
        .name           = "disk",
        .groups         = disk_attr_groups,
        .release        = disk_release,
+       .devnode        = block_devnode,
 };
 
 #ifdef CONFIG_PROC_FS
@@ -1011,7 +1072,7 @@ static int diskstats_show(struct seq_file *seqf, void *v)
                                "\n\n");
        */
  
-       disk_part_iter_init(&piter, gp, DISK_PITER_INCL_PART0);
+       disk_part_iter_init(&piter, gp, DISK_PITER_INCL_EMPTY_PART0);
        while ((hd = disk_part_iter_next(&piter))) {
                cpu = part_stat_lock();
                part_round_stats(cpu, hd);
@@ -1028,7 +1089,7 @@ static int diskstats_show(struct seq_file *seqf, void *v)
                           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,
+                          part_in_flight(hd),
                           jiffies_to_msecs(part_stat_read(hd, io_ticks)),
                           jiffies_to_msecs(part_stat_read(hd, time_in_queue))
                        );
@@ -1190,6 +1251,16 @@ void put_disk(struct gendisk *disk)
 
 EXPORT_SYMBOL(put_disk);
 
+static void set_disk_ro_uevent(struct gendisk *gd, int ro)
+{
+       char event[] = "DISK_RO=1";
+       char *envp[] = { event, NULL };
+
+       if (!ro)
+               event[8] = '0';
+       kobject_uevent_env(&disk_to_dev(gd)->kobj, KOBJ_CHANGE, envp);
+}
+
 void set_device_ro(struct block_device *bdev, int flag)
 {
        bdev->bd_part->policy = flag;
@@ -1202,8 +1273,12 @@ void set_disk_ro(struct gendisk *disk, int flag)
        struct disk_part_iter piter;
        struct hd_struct *part;
 
-       disk_part_iter_init(&piter, disk,
-                           DISK_PITER_INCL_EMPTY | DISK_PITER_INCL_PART0);
+       if (disk->part0.policy != flag) {
+               set_disk_ro_uevent(disk, flag);
+               disk->part0.policy = flag;
+       }
+
+       disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY);
        while ((part = disk_part_iter_next(&piter)))
                part->policy = flag;
        disk_part_iter_exit(&piter);