Merge tag 'for-5.11/dm-changes' of git://git.kernel.org/pub/scm/linux/kernel/git...
[sfrench/cifs-2.6.git] / drivers / md / dm.c
index 4e0cbfe3f14d434f9fefeae37b1d6f71e79b4f63..b3c3c8b4cb428f587dbe9840b276fdc14d8fd630 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;
@@ -1274,8 +1277,7 @@ static blk_qc_t __map_bio(struct dm_target_io *tio)
                break;
        case DM_MAPIO_REMAPPED:
                /* the bio has been remapped so dispatch it */
-               trace_block_bio_remap(clone->bi_disk->queue, clone,
-                                     bio_dev(io->orig_bio), sector);
+               trace_block_bio_remap(clone, bio_dev(io->orig_bio), sector);
                ret = submit_bio_noacct(clone);
                break;
        case DM_MAPIO_KILL:
@@ -1420,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);
@@ -1590,7 +1586,7 @@ static blk_qc_t __split_and_process_bio(struct mapped_device *md,
                ci.sector_count = bio_sectors(bio);
                while (ci.sector_count && !error) {
                        error = __split_and_process_non_flush(&ci);
-                       if (current->bio_list && ci.sector_count && !error) {
+                       if (ci.sector_count && !error) {
                                /*
                                 * Remainder must be passed to submit_bio_noacct()
                                 * so that it gets handled *after* bios already submitted
@@ -1611,12 +1607,12 @@ 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();
 
                                bio_chain(b, bio);
-                               trace_block_split(md->queue, b, bio->bi_iter.bi_sector);
+                               trace_block_split(b, bio->bi_iter.bi_sector);
                                ret = submit_bio_noacct(bio);
                                break;
                        }
@@ -1748,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);
@@ -1844,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 */
@@ -1972,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);
 
@@ -2256,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) {
@@ -2391,27 +2377,19 @@ static int lock_fs(struct mapped_device *md)
 {
        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;
+       r = freeze_bdev(md->disk->part0);
+       if (!r)
+               set_bit(DMF_FROZEN, &md->flags);
+       return r;
 }
 
 static void unlock_fs(struct mapped_device *md)
 {
        if (!test_bit(DMF_FROZEN, &md->flags))
                return;
-
-       thaw_bdev(md->bdev, md->frozen_sb);
-       md->frozen_sb = NULL;
+       thaw_bdev(md->disk->part0);
        clear_bit(DMF_FROZEN, &md->flags);
 }