dm-snap: don't use map_info map_info->ptr was used in dm-snap to indicate if the bio was tracked. If map_info->ptr was non-NULL, the bio was linked in tracked_chunk_hash. This patch removes the use of map_info->ptr. We determine if the bio was tracked based on hlist_unhashed(&c->node) --- if hlist_unhashed is true, the bio is not tracked, if it is false, the bio is tracked. Signed-off-by: Mikulas Patocka --- drivers/md/dm-snap.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) Index: linux-3.7-rc6/drivers/md/dm-snap.c =================================================================== --- linux-3.7-rc6.orig/drivers/md/dm-snap.c 2012-11-19 21:17:10.000000000 +0100 +++ linux-3.7-rc6/drivers/md/dm-snap.c 2012-11-19 21:17:55.000000000 +0100 @@ -193,9 +193,19 @@ struct dm_snap_tracked_chunk { chunk_t chunk; }; -static struct dm_snap_tracked_chunk *track_chunk(struct dm_snapshot *s, - struct bio *bio, - chunk_t chunk) +static void init_tracked_chunk(struct bio *bio) +{ + struct dm_snap_tracked_chunk *c = dm_bio_get_per_request_data(bio, sizeof(struct dm_snap_tracked_chunk)); + INIT_HLIST_NODE(&c->node); +} + +static bool is_bio_tracked(struct bio *bio) +{ + struct dm_snap_tracked_chunk *c = dm_bio_get_per_request_data(bio, sizeof(struct dm_snap_tracked_chunk)); + return !hlist_unhashed(&c->node); +} + +static void track_chunk(struct dm_snapshot *s, struct bio *bio, chunk_t chunk) { struct dm_snap_tracked_chunk *c = dm_bio_get_per_request_data(bio, sizeof(struct dm_snap_tracked_chunk)); @@ -205,13 +215,11 @@ static struct dm_snap_tracked_chunk *tra hlist_add_head(&c->node, &s->tracked_chunk_hash[DM_TRACKED_CHUNK_HASH(chunk)]); spin_unlock_irq(&s->tracked_chunk_lock); - - return c; } -static void stop_tracking_chunk(struct dm_snapshot *s, - struct dm_snap_tracked_chunk *c) +static void stop_tracking_chunk(struct dm_snapshot *s, struct bio *bio) { + struct dm_snap_tracked_chunk *c = dm_bio_get_per_request_data(bio, sizeof(struct dm_snap_tracked_chunk)); unsigned long flags; spin_lock_irqsave(&s->tracked_chunk_lock, flags); @@ -1571,6 +1579,8 @@ static int snapshot_map(struct dm_target chunk_t chunk; struct dm_snap_pending_exception *pe = NULL; + init_tracked_chunk(bio); + if (bio->bi_rw & REQ_FLUSH) { bio->bi_bdev = s->cow->bdev; return DM_MAPIO_REMAPPED; @@ -1655,7 +1665,7 @@ static int snapshot_map(struct dm_target } } else { bio->bi_bdev = s->origin->bdev; - map_context->ptr = track_chunk(s, bio, chunk); + track_chunk(s, bio, chunk); } out_unlock: @@ -1684,12 +1694,13 @@ static int snapshot_merge_map(struct dm_ int r = DM_MAPIO_REMAPPED; chunk_t chunk; + init_tracked_chunk(bio); + if (bio->bi_rw & REQ_FLUSH) { if (!dm_bio_get_target_request_nr(bio)) bio->bi_bdev = s->origin->bdev; else bio->bi_bdev = s->cow->bdev; - map_context->ptr = NULL; return DM_MAPIO_REMAPPED; } @@ -1718,7 +1729,7 @@ static int snapshot_merge_map(struct dm_ remap_exception(s, e, bio, chunk); if (bio_rw(bio) == WRITE) - map_context->ptr = track_chunk(s, bio, chunk); + track_chunk(s, bio, chunk); goto out_unlock; } @@ -1740,10 +1751,9 @@ static int snapshot_end_io(struct dm_tar int error, union map_info *map_context) { struct dm_snapshot *s = ti->private; - struct dm_snap_tracked_chunk *c = map_context->ptr; - if (c) - stop_tracking_chunk(s, c); + if (is_bio_tracked(bio)) + stop_tracking_chunk(s, bio); return 0; }