diff options
author | Mikulas Patocka <mpatocka@redhat.com> | 2012-12-21 15:23:41 -0500 |
---|---|---|
committer | Alasdair G Kergon <agk@redhat.com> | 2012-12-21 15:23:41 -0500 |
commit | ee18026ac69efba804144541171299efd41747d2 (patch) | |
tree | 8e6e9e85114a6b6568b8325aca750428150d4b95 /drivers/md | |
parent | 59c3d2c6a12ff580b2c19c3925af4f4552639f8a (diff) |
dm snapshot: do not use map_context
Eliminate struct map_info from dm-snap.
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 <mpatocka@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/dm-snap.c | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c index b7e179cdc5a..e1ecacf2456 100644 --- a/drivers/md/dm-snap.c +++ b/drivers/md/dm-snap.c | |||
@@ -190,9 +190,19 @@ struct dm_snap_tracked_chunk { | |||
190 | chunk_t chunk; | 190 | chunk_t chunk; |
191 | }; | 191 | }; |
192 | 192 | ||
193 | static struct dm_snap_tracked_chunk *track_chunk(struct dm_snapshot *s, | 193 | static void init_tracked_chunk(struct bio *bio) |
194 | struct bio *bio, | 194 | { |
195 | chunk_t chunk) | 195 | struct dm_snap_tracked_chunk *c = dm_per_bio_data(bio, sizeof(struct dm_snap_tracked_chunk)); |
196 | INIT_HLIST_NODE(&c->node); | ||
197 | } | ||
198 | |||
199 | static bool is_bio_tracked(struct bio *bio) | ||
200 | { | ||
201 | struct dm_snap_tracked_chunk *c = dm_per_bio_data(bio, sizeof(struct dm_snap_tracked_chunk)); | ||
202 | return !hlist_unhashed(&c->node); | ||
203 | } | ||
204 | |||
205 | static void track_chunk(struct dm_snapshot *s, struct bio *bio, chunk_t chunk) | ||
196 | { | 206 | { |
197 | struct dm_snap_tracked_chunk *c = dm_per_bio_data(bio, sizeof(struct dm_snap_tracked_chunk)); | 207 | struct dm_snap_tracked_chunk *c = dm_per_bio_data(bio, sizeof(struct dm_snap_tracked_chunk)); |
198 | 208 | ||
@@ -202,13 +212,11 @@ static struct dm_snap_tracked_chunk *track_chunk(struct dm_snapshot *s, | |||
202 | hlist_add_head(&c->node, | 212 | hlist_add_head(&c->node, |
203 | &s->tracked_chunk_hash[DM_TRACKED_CHUNK_HASH(chunk)]); | 213 | &s->tracked_chunk_hash[DM_TRACKED_CHUNK_HASH(chunk)]); |
204 | spin_unlock_irq(&s->tracked_chunk_lock); | 214 | spin_unlock_irq(&s->tracked_chunk_lock); |
205 | |||
206 | return c; | ||
207 | } | 215 | } |
208 | 216 | ||
209 | static void stop_tracking_chunk(struct dm_snapshot *s, | 217 | static void stop_tracking_chunk(struct dm_snapshot *s, struct bio *bio) |
210 | struct dm_snap_tracked_chunk *c) | ||
211 | { | 218 | { |
219 | struct dm_snap_tracked_chunk *c = dm_per_bio_data(bio, sizeof(struct dm_snap_tracked_chunk)); | ||
212 | unsigned long flags; | 220 | unsigned long flags; |
213 | 221 | ||
214 | spin_lock_irqsave(&s->tracked_chunk_lock, flags); | 222 | spin_lock_irqsave(&s->tracked_chunk_lock, flags); |
@@ -1568,6 +1576,8 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio, | |||
1568 | chunk_t chunk; | 1576 | chunk_t chunk; |
1569 | struct dm_snap_pending_exception *pe = NULL; | 1577 | struct dm_snap_pending_exception *pe = NULL; |
1570 | 1578 | ||
1579 | init_tracked_chunk(bio); | ||
1580 | |||
1571 | if (bio->bi_rw & REQ_FLUSH) { | 1581 | if (bio->bi_rw & REQ_FLUSH) { |
1572 | bio->bi_bdev = s->cow->bdev; | 1582 | bio->bi_bdev = s->cow->bdev; |
1573 | return DM_MAPIO_REMAPPED; | 1583 | return DM_MAPIO_REMAPPED; |
@@ -1652,7 +1662,7 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio, | |||
1652 | } | 1662 | } |
1653 | } else { | 1663 | } else { |
1654 | bio->bi_bdev = s->origin->bdev; | 1664 | bio->bi_bdev = s->origin->bdev; |
1655 | map_context->ptr = track_chunk(s, bio, chunk); | 1665 | track_chunk(s, bio, chunk); |
1656 | } | 1666 | } |
1657 | 1667 | ||
1658 | out_unlock: | 1668 | out_unlock: |
@@ -1681,12 +1691,13 @@ static int snapshot_merge_map(struct dm_target *ti, struct bio *bio, | |||
1681 | int r = DM_MAPIO_REMAPPED; | 1691 | int r = DM_MAPIO_REMAPPED; |
1682 | chunk_t chunk; | 1692 | chunk_t chunk; |
1683 | 1693 | ||
1694 | init_tracked_chunk(bio); | ||
1695 | |||
1684 | if (bio->bi_rw & REQ_FLUSH) { | 1696 | if (bio->bi_rw & REQ_FLUSH) { |
1685 | if (!dm_bio_get_target_request_nr(bio)) | 1697 | if (!dm_bio_get_target_request_nr(bio)) |
1686 | bio->bi_bdev = s->origin->bdev; | 1698 | bio->bi_bdev = s->origin->bdev; |
1687 | else | 1699 | else |
1688 | bio->bi_bdev = s->cow->bdev; | 1700 | bio->bi_bdev = s->cow->bdev; |
1689 | map_context->ptr = NULL; | ||
1690 | return DM_MAPIO_REMAPPED; | 1701 | return DM_MAPIO_REMAPPED; |
1691 | } | 1702 | } |
1692 | 1703 | ||
@@ -1715,7 +1726,7 @@ static int snapshot_merge_map(struct dm_target *ti, struct bio *bio, | |||
1715 | remap_exception(s, e, bio, chunk); | 1726 | remap_exception(s, e, bio, chunk); |
1716 | 1727 | ||
1717 | if (bio_rw(bio) == WRITE) | 1728 | if (bio_rw(bio) == WRITE) |
1718 | map_context->ptr = track_chunk(s, bio, chunk); | 1729 | track_chunk(s, bio, chunk); |
1719 | goto out_unlock; | 1730 | goto out_unlock; |
1720 | } | 1731 | } |
1721 | 1732 | ||
@@ -1737,10 +1748,9 @@ static int snapshot_end_io(struct dm_target *ti, struct bio *bio, | |||
1737 | int error, union map_info *map_context) | 1748 | int error, union map_info *map_context) |
1738 | { | 1749 | { |
1739 | struct dm_snapshot *s = ti->private; | 1750 | struct dm_snapshot *s = ti->private; |
1740 | struct dm_snap_tracked_chunk *c = map_context->ptr; | ||
1741 | 1751 | ||
1742 | if (c) | 1752 | if (is_bio_tracked(bio)) |
1743 | stop_tracking_chunk(s, c); | 1753 | stop_tracking_chunk(s, bio); |
1744 | 1754 | ||
1745 | return 0; | 1755 | return 0; |
1746 | } | 1756 | } |