dm thin: change data device's flush_bio to be member of struct pool
authorMikulas Patocka <mpatocka@redhat.com>
Mon, 13 Jan 2020 20:41:53 +0000 (15:41 -0500)
committerMike Snitzer <snitzer@redhat.com>
Wed, 15 Jan 2020 01:23:13 +0000 (20:23 -0500)
With commit fe64369163c5 ("dm thin: don't allow changing data device
during thin-pool load") it is now possible to re-parent the data
device's flush_bio from the pool_c to pool structure.  Doing so offers
improved lifetime guarantees for the flush_bio so that the call to
dm_pool_register_pre_commit_callback can now be done safely from
pool_ctr().

Depends-on: fe64369163c5 ("dm thin: don't allow changing data device during thin-pool load")
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
drivers/md/dm-thin.c

index 4fb6e89c87862ddb5f7b96f546ca17022e35247c..fa8d5464c1fb51f438846f7929098bc00921a1e8 100644 (file)
@@ -282,6 +282,8 @@ struct pool {
        struct dm_bio_prison_cell **cell_sort_array;
 
        mempool_t mapping_pool;
+
+       struct bio flush_bio;
 };
 
 static void metadata_operation_failed(struct pool *pool, const char *op, int r);
@@ -329,7 +331,6 @@ struct pool_c {
        dm_block_t low_water_blocks;
        struct pool_features requested_pf; /* Features requested during table load */
        struct pool_features adjusted_pf;  /* Features used after adjusting for constituent devices */
-       struct bio flush_bio;
 };
 
 /*
@@ -2925,6 +2926,7 @@ static void __pool_destroy(struct pool *pool)
        if (pool->next_mapping)
                mempool_free(pool->next_mapping, &pool->mapping_pool);
        mempool_exit(&pool->mapping_pool);
+       bio_uninit(&pool->flush_bio);
        dm_deferred_set_destroy(pool->shared_read_ds);
        dm_deferred_set_destroy(pool->all_io_ds);
        kfree(pool);
@@ -3005,6 +3007,7 @@ static struct pool *pool_create(struct mapped_device *pool_md,
        pool->low_water_triggered = false;
        pool->suspended = true;
        pool->out_of_data_space = false;
+       bio_init(&pool->flush_bio, NULL, 0);
 
        pool->shared_read_ds = dm_deferred_set_create();
        if (!pool->shared_read_ds) {
@@ -3132,7 +3135,6 @@ static void pool_dtr(struct dm_target *ti)
        __pool_dec(pt->pool);
        dm_put_device(ti, pt->metadata_dev);
        dm_put_device(ti, pt->data_dev);
-       bio_uninit(&pt->flush_bio);
        kfree(pt);
 
        mutex_unlock(&dm_thin_pool_table.mutex);
@@ -3211,11 +3213,11 @@ static void metadata_low_callback(void *context)
  */
 static int metadata_pre_commit_callback(void *context)
 {
-       struct pool_c *pt = context;
-       struct bio *flush_bio = &pt->flush_bio;
+       struct pool *pool = context;
+       struct bio *flush_bio = &pool->flush_bio;
 
        bio_reset(flush_bio);
-       bio_set_dev(flush_bio, pt->data_dev->bdev);
+       bio_set_dev(flush_bio, pool->data_dev);
        flush_bio->bi_opf = REQ_OP_WRITE | REQ_PREFLUSH;
 
        return submit_bio_wait(flush_bio);
@@ -3389,7 +3391,6 @@ static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv)
        pt->data_dev = data_dev;
        pt->low_water_blocks = low_water_blocks;
        pt->adjusted_pf = pt->requested_pf = pf;
-       bio_init(&pt->flush_bio, NULL, 0);
        ti->num_flush_bios = 1;
 
        /*
@@ -3416,6 +3417,9 @@ static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv)
        if (r)
                goto out_flags_changed;
 
+       dm_pool_register_pre_commit_callback(pool->pmd,
+                                            metadata_pre_commit_callback, pool);
+
        pt->callbacks.congested_fn = pool_is_congested;
        dm_table_add_target_callbacks(ti->table, &pt->callbacks);
 
@@ -3578,9 +3582,6 @@ static int pool_preresume(struct dm_target *ti)
        if (r)
                return r;
 
-       dm_pool_register_pre_commit_callback(pool->pmd,
-                                            metadata_pre_commit_callback, pt);
-
        r = maybe_resize_data_dev(ti, &need_commit1);
        if (r)
                return r;