History

dm thin: dont use map_context

This patch removes endio_hook_pool from dm-thin and uses per-bio data instead. This patch removes any use of map_info in preparation for the next patch that removes map_info from bio-based device mapper.

Mikulas Patocka committed 13 years ago

Commit 59c3d2c1 parent 0045d611 file · +13 −36Browse files

Unified · Split

drivers/md/dm-thin.c+13−36
@@ -186,7 +186,6 @@ struct pool { · 185 unmodified lines
186186
187187 struct dm_thin_new_mapping *next_mapping;
188188 mempool_t *mapping_pool;
189− mempool_t *endio_hook_pool;
190189
191190 process_bio_fn process_bio;
192191 process_bio_fn process_discard;
@@ -304,7 +303,7 @@ static void __requeue_bio_list(struct thin_c *tc, struct bio_list *master) · 111 unmodified lines
304303 bio_list_init(master);
305304
306305 while ((bio = bio_list_pop(&bios))) {
307− struct dm_thin_endio_hook *h = dm_get_mapinfo(bio)->ptr;
306+ struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook));
308307
309308 if (h->tc == tc)
310309 bio_endio(bio, DM_ENDIO_REQUEUE);
@@ -375,7 +374,7 @@ static void inc_all_io_entry(struct pool *pool, struct bio *bio) · 64 unmodified lines
375374 if (bio->bi_rw & REQ_DISCARD)
376375 return;
377376
378− h = dm_get_mapinfo(bio)->ptr;
377+ h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook));
379378 h->all_io_entry = dm_deferred_entry_inc(pool->all_io_ds);
380379 }
381380
@@ -485,7 +484,7 @@ static void copy_complete(int read_err, unsigned long write_err, void *context) · 103 unmodified lines
485484 static void overwrite_endio(struct bio *bio, int err)
486485 {
487486 unsigned long flags;
488− struct dm_thin_endio_hook *h = dm_get_mapinfo(bio)->ptr;
487+ struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook));
489488 struct dm_thin_new_mapping *m = h->overwrite_mapping;
490489 struct pool *pool = m->tc->pool;
491490
@@ -714,7 +713,7 @@ static void schedule_copy(struct thin_c *tc, dm_block_t virt_block, · 222 unmodified lines
714713 * bio immediately. Otherwise we use kcopyd to clone the data first.
715714 */
716715 if (io_overwrites_block(pool, bio)) {
717− struct dm_thin_endio_hook *h = dm_get_mapinfo(bio)->ptr;
716+ struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook));
718717
719718 h->overwrite_mapping = m;
720719 m->bio = bio;
@@ -784,7 +783,7 @@ static void schedule_zero(struct thin_c *tc, dm_block_t virt_block, · 63 unmodified lines
784783 process_prepared_mapping(m);
785784
786785 else if (io_overwrites_block(pool, bio)) {
787− struct dm_thin_endio_hook *h = dm_get_mapinfo(bio)->ptr;
786+ struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook));
788787
789788 h->overwrite_mapping = m;
790789 m->bio = bio;
@@ -899,7 +898,7 @@ static int alloc_data_block(struct thin_c *tc, dm_block_t *result) · 108 unmodified lines
899898 */
900899 static void retry_on_resume(struct bio *bio)
901900 {
902− struct dm_thin_endio_hook *h = dm_get_mapinfo(bio)->ptr;
901+ struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook));
903902 struct thin_c *tc = h->tc;
904903 struct pool *pool = tc->pool;
905904 unsigned long flags;
@@ -1051,7 +1050,7 @@ static void process_shared_bio(struct thin_c *tc, struct bio *bio, · 145 unmodified lines
10511050 if (bio_data_dir(bio) == WRITE && bio->bi_size)
10521051 break_sharing(tc, bio, block, &key, lookup_result, cell);
10531052 else {
1054− struct dm_thin_endio_hook *h = dm_get_mapinfo(bio)->ptr;
1053+ struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook));
10551054
10561055 h->shared_read_entry = dm_deferred_entry_inc(pool->shared_read_ds);
10571056 inc_all_io_entry(pool, bio);
@@ -1226,7 +1225,7 @@ static void process_deferred_bios(struct pool *pool) · 168 unmodified lines
12261225 spin_unlock_irqrestore(&pool->lock, flags);
12271226
12281227 while ((bio = bio_list_pop(&bios))) {
1229− struct dm_thin_endio_hook *h = dm_get_mapinfo(bio)->ptr;
1228+ struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook));
12301229 struct thin_c *tc = h->tc;
12311230
12321231 /*
@@ -1359,17 +1358,14 @@ static void thin_defer_bio(struct thin_c *tc, struct bio *bio) · 126 unmodified lines
13591358 wake_worker(pool);
13601359 }
13611360
1362−static struct dm_thin_endio_hook *thin_hook_bio(struct thin_c *tc, struct bio *bio)
1361+static void thin_hook_bio(struct thin_c *tc, struct bio *bio)
13631362 {
1364− struct pool *pool = tc->pool;
1365− struct dm_thin_endio_hook *h = mempool_alloc(pool->endio_hook_pool, GFP_NOIO);
1363+ struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook));
13661364
13671365 h->tc = tc;
13681366 h->shared_read_entry = NULL;
13691367 h->all_io_entry = NULL;
13701368 h->overwrite_mapping = NULL;
1371−
1372− return h;
13731369 }
13741370
13751371 /*
@@ -1386,7 +1382,7 @@ static int thin_bio_map(struct dm_target *ti, struct bio *bio, · 10 unmodified lines
13861382 struct dm_bio_prison_cell *cell1, *cell2;
13871383 struct dm_cell_key key;
13881384
1389− map_context->ptr = thin_hook_bio(tc, bio);
1385+ thin_hook_bio(tc, bio);
13901386
13911387 if (get_pool_mode(tc->pool) == PM_FAIL) {
13921388 bio_io_error(bio);
@@ -1595,14 +1591,12 @@ static void __pool_destroy(struct pool *pool) · 202 unmodified lines
15951591 if (pool->next_mapping)
15961592 mempool_free(pool->next_mapping, pool->mapping_pool);
15971593 mempool_destroy(pool->mapping_pool);
1598− mempool_destroy(pool->endio_hook_pool);
15991594 dm_deferred_set_destroy(pool->shared_read_ds);
16001595 dm_deferred_set_destroy(pool->all_io_ds);
16011596 kfree(pool);
16021597 }
16031598
16041599 static struct kmem_cache *_new_mapping_cache;
1605−static struct kmem_cache *_endio_hook_cache;
16061600
16071601 static struct pool *pool_create(struct mapped_device *pool_md,
16081602 struct block_device *metadata_dev,
@@ -1696,13 +1690,6 @@ static struct pool *pool_create(struct mapped_device *pool_md, · 87 unmodified lines
16961690 goto bad_mapping_pool;
16971691 }
16981692
1699− pool->endio_hook_pool = mempool_create_slab_pool(ENDIO_HOOK_POOL_SIZE,
1700− _endio_hook_cache);
1701− if (!pool->endio_hook_pool) {
1702− *error = "Error creating pool's endio_hook mempool";
1703− err_p = ERR_PTR(-ENOMEM);
1704− goto bad_endio_hook_pool;
1705− }
17061693 pool->ref_count = 1;
17071694 pool->last_commit_jiffies = jiffies;
17081695 pool->pool_md = pool_md;
@@ -1711,8 +1698,6 @@ static struct pool *pool_create(struct mapped_device *pool_md, · 2 unmodified lines
17111698
17121699 return pool;
17131700
1714−bad_endio_hook_pool:
1715− mempool_destroy(pool->mapping_pool);
17161701 bad_mapping_pool:
17171702 dm_deferred_set_destroy(pool->all_io_ds);
17181703 bad_all_io_ds:
@@ -2607,6 +2592,7 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv) · 888 unmodified lines
26072592
26082593 ti->num_flush_requests = 1;
26092594 ti->flush_supported = true;
2595+ ti->per_bio_data_size = sizeof(struct dm_thin_endio_hook);
26102596
26112597 /* In case the pool supports discards, pass them on. */
26122598 if (tc->pool->pf.discard_enabled) {
@@ -2653,7 +2639,7 @@ static int thin_endio(struct dm_target *ti, · 40 unmodified lines
26532639 union map_info *map_context)
26542640 {
26552641 unsigned long flags;
2656− struct dm_thin_endio_hook *h = map_context->ptr;
2642+ struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook));
26572643 struct list_head work;
26582644 struct dm_thin_new_mapping *m, *tmp;
26592645 struct pool *pool = h->tc->pool;
@@ -2683,8 +2669,6 @@ static int thin_endio(struct dm_target *ti, · 23 unmodified lines
26832669 }
26842670 }
26852671
2686− mempool_free(h, pool->endio_hook_pool);
2687−
26882672 return 0;
26892673 }
26902674
@@ -2813,14 +2797,8 @@ static int __init dm_thin_init(void) · 122 unmodified lines
28132797 if (!_new_mapping_cache)
28142798 goto bad_new_mapping_cache;
28152799
2816− _endio_hook_cache = KMEM_CACHE(dm_thin_endio_hook, 0);
2817− if (!_endio_hook_cache)
2818− goto bad_endio_hook_cache;
2819−
28202800 return 0;
28212801
2822−bad_endio_hook_cache:
2823− kmem_cache_destroy(_new_mapping_cache);
28242802 bad_new_mapping_cache:
28252803 dm_unregister_target(&pool_target);
28262804 bad_pool_target:
@@ -2835,7 +2813,6 @@ static void dm_thin_exit(void) · 8 unmodified lines
28352813 dm_unregister_target(&pool_target);
28362814
28372815 kmem_cache_destroy(_new_mapping_cache);
2838− kmem_cache_destroy(_endio_hook_cache);
28392816 }
28402817
28412818 module_init(dm_thin_init);