dm: set the static flush bio device on demand
[sfrench/cifs-2.6.git] / drivers / md / dm.c
index c510179a7f845eb4f25e5818e39e54eb9afadcfb..ab72d79775ee36bf7d41c1257e58be2209087d5a 100644 (file)
@@ -1417,10 +1417,21 @@ static int __send_empty_flush(struct clone_info *ci)
        unsigned target_nr = 0;
        struct dm_target *ti;
 
+       /*
+        * Empty flush uses a statically initialized bio, &md->flush_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);
 
+       bio_disassociate_blkg(ci->bio);
+
        return 0;
 }
 
@@ -1896,7 +1907,7 @@ static struct mapped_device *alloc_dev(int minor)
        INIT_LIST_HEAD(&md->table_devices);
        spin_lock_init(&md->uevent_lock);
 
-       md->queue = blk_alloc_queue_node(GFP_KERNEL, numa_node_id, NULL);
+       md->queue = blk_alloc_queue_node(GFP_KERNEL, numa_node_id);
        if (!md->queue)
                goto bad;
        md->queue->queuedata = md;
@@ -1939,7 +1950,6 @@ static struct mapped_device *alloc_dev(int minor)
                goto bad;
 
        bio_init(&md->flush_bio, NULL, 0);
-       bio_set_dev(&md->flush_bio, md->bdev);
        md->flush_bio.bi_opf = REQ_OP_WRITE | REQ_PREFLUSH | REQ_SYNC;
 
        dm_stats_init(&md->stats);