block: switch partition lookup to use struct block_device
[linux-block.git] / drivers / md / dm.c
index c18fc25485186de70b172d5b80f4e3a190fd419b..176adcff56b3802f94a4fbb4ade226f1b4c9aa39 100644 (file)
@@ -570,7 +570,10 @@ static int dm_blk_ioctl(struct block_device *bdev, fmode_t mode,
                }
        }
 
-       r =  __blkdev_driver_ioctl(bdev, mode, cmd, arg);
+       if (!bdev->bd_disk->fops->ioctl)
+               r = -ENOTTY;
+       else
+               r = bdev->bd_disk->fops->ioctl(bdev, mode, cmd, arg);
 out:
        dm_unprepare_ioctl(md, srcu_idx);
        return r;
@@ -1419,18 +1422,12 @@ static int __send_empty_flush(struct clone_info *ci)
         */
        bio_init(&flush_bio, NULL, 0);
        flush_bio.bi_opf = REQ_OP_WRITE | REQ_PREFLUSH | REQ_SYNC;
+       flush_bio.bi_disk = ci->io->md->disk;
+       bio_associate_blkg(&flush_bio);
+
        ci->bio = &flush_bio;
        ci->sector_count = 0;
 
-       /*
-        * Empty flush uses a statically initialized bio, as the base for
-        * cloning.  However, blkg association requires that a bdev is
-        * associated with a gendisk, which doesn't happen until the bdev is
-        * opened.  So, blkg association is done at issue time of the flush
-        * rather than when the device is created in alloc_dev().
-        */
-       bio_set_dev(ci->bio, ci->io->md->bdev);
-
        BUG_ON(bio_has_data(ci->bio));
        while ((ti = dm_table_get_target(ci->map, target_nr++)))
                __send_duplicate_bios(ci, ti, ti->num_flush_bios, NULL);
@@ -1610,7 +1607,7 @@ static blk_qc_t __split_and_process_bio(struct mapped_device *md,
                                 * (by eliminating DM's splitting and just using bio_split)
                                 */
                                part_stat_lock();
-                               __dm_part_stat_sub(&dm_disk(md)->part0,
+                               __dm_part_stat_sub(dm_disk(md)->part0,
                                                   sectors[op_stat_group(bio_op(bio))], ci.sector_count);
                                part_stat_unlock();
 
@@ -1747,11 +1744,6 @@ static void cleanup_mapped_device(struct mapped_device *md)
 
        cleanup_srcu_struct(&md->io_barrier);
 
-       if (md->bdev) {
-               bdput(md->bdev);
-               md->bdev = NULL;
-       }
-
        mutex_destroy(&md->suspend_lock);
        mutex_destroy(&md->type_lock);
        mutex_destroy(&md->table_devices_lock);
@@ -1843,10 +1835,6 @@ static struct mapped_device *alloc_dev(int minor)
        if (!md->wq)
                goto bad;
 
-       md->bdev = bdget_disk(md->disk, 0);
-       if (!md->bdev)
-               goto bad;
-
        dm_stats_init(&md->stats);
 
        /* Populate the mapping, nobody knows we exist yet */
@@ -1971,8 +1959,7 @@ static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t,
        if (size != dm_get_size(md))
                memset(&md->geometry, 0, sizeof(md->geometry));
 
-       set_capacity(md->disk, size);
-       bd_set_nr_sectors(md->bdev, size);
+       set_capacity_and_notify(md->disk, size);
 
        dm_table_event_callback(t, event_callback, md);
 
@@ -2255,7 +2242,7 @@ EXPORT_SYMBOL_GPL(dm_put);
 static bool md_in_flight_bios(struct mapped_device *md)
 {
        int cpu;
-       struct hd_struct *part = &dm_disk(md)->part0;
+       struct block_device *part = dm_disk(md)->part0;
        long sum = 0;
 
        for_each_possible_cpu(cpu) {
@@ -2388,29 +2375,33 @@ out:
  */
 static int lock_fs(struct mapped_device *md)
 {
+       struct block_device *bdev;
        int r;
 
-       WARN_ON(md->frozen_sb);
+       WARN_ON(test_bit(DMF_FROZEN, &md->flags));
 
-       md->frozen_sb = freeze_bdev(md->bdev);
-       if (IS_ERR(md->frozen_sb)) {
-               r = PTR_ERR(md->frozen_sb);
-               md->frozen_sb = NULL;
-               return r;
-       }
-
-       set_bit(DMF_FROZEN, &md->flags);
-
-       return 0;
+       bdev = bdget_disk(md->disk, 0);
+       if (!bdev)
+               return -ENOMEM;
+       r = freeze_bdev(bdev);
+       bdput(bdev);
+       if (!r)
+               set_bit(DMF_FROZEN, &md->flags);
+       return r;
 }
 
 static void unlock_fs(struct mapped_device *md)
 {
+       struct block_device *bdev;
+
        if (!test_bit(DMF_FROZEN, &md->flags))
                return;
 
-       thaw_bdev(md->bdev, md->frozen_sb);
-       md->frozen_sb = NULL;
+       bdev = bdget_disk(md->disk, 0);
+       if (!bdev)
+               return;
+       thaw_bdev(bdev);
+       bdput(bdev);
        clear_bit(DMF_FROZEN, &md->flags);
 }