dm: remove the block_device reference in struct mapped_device
authorChristoph Hellwig <hch@lst.de>
Fri, 27 Nov 2020 15:21:42 +0000 (16:21 +0100)
committerJens Axboe <axboe@kernel.dk>
Tue, 1 Dec 2020 21:53:39 +0000 (14:53 -0700)
Get rid of the long-lasting struct block_device reference in
struct mapped_device.  The only remaining user is the freeze code,
where we can trivially look up the block device at freeze time
and release the reference at thaw time.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/md/dm-core.h
drivers/md/dm.c

index aace147effcacb460c86648a2d04439fc45b3f5b..086d293c2b036cf506d8303e8a2f8667fd3754ba 100644 (file)
@@ -102,8 +102,6 @@ struct mapped_device {
        /* kobject and completion */
        struct dm_kobject_holder kobj_holder;
 
-       struct block_device *bdev;
-
        struct dm_stats stats;
 
        /* for blk-mq request-based DM support */
index ab0a8335f098d96f2f3aa8c6d16fd146527295ff..48051db006f30cf82865ebe91e11eff974d195df 100644 (file)
@@ -1744,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);
@@ -1840,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 */
@@ -2384,11 +2375,16 @@ out:
  */
 static int lock_fs(struct mapped_device *md)
 {
+       struct block_device *bdev;
        int r;
 
        WARN_ON(test_bit(DMF_FROZEN, &md->flags));
 
-       r = freeze_bdev(md->bdev);
+       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;
@@ -2396,9 +2392,16 @@ static int lock_fs(struct mapped_device *md)
 
 static void unlock_fs(struct mapped_device *md)
 {
+       struct block_device *bdev;
+
        if (!test_bit(DMF_FROZEN, &md->flags))
                return;
-       thaw_bdev(md->bdev);
+
+       bdev = bdget_disk(md->disk, 0);
+       if (!bdev)
+               return;
+       thaw_bdev(bdev);
+       bdput(bdev);
        clear_bit(DMF_FROZEN, &md->flags);
 }