Commit ee18026ac69efba804144541171299efd41747d2

Authored by Mikulas Patocka
Committed by Alasdair G Kergon
1 parent 59c3d2c6a1

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>

Showing 1 changed file with 23 additions and 13 deletions Side-by-side Diff

drivers/md/dm-snap.c
... ... @@ -190,25 +190,33 @@
190 190 chunk_t chunk;
191 191 };
192 192  
193   -static struct dm_snap_tracked_chunk *track_chunk(struct dm_snapshot *s,
194   - struct bio *bio,
195   - chunk_t chunk)
  193 +static void init_tracked_chunk(struct bio *bio)
196 194 {
197 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 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)
  206 +{
  207 + struct dm_snap_tracked_chunk *c = dm_per_bio_data(bio, sizeof(struct dm_snap_tracked_chunk));
  208 +
199 209 c->chunk = chunk;
200 210  
201 211 spin_lock_irq(&s->tracked_chunk_lock);
202 212 hlist_add_head(&c->node,
203 213 &s->tracked_chunk_hash[DM_TRACKED_CHUNK_HASH(chunk)]);
204 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,
210   - struct dm_snap_tracked_chunk *c)
  217 +static void stop_tracking_chunk(struct dm_snapshot *s, struct bio *bio)
211 218 {
  219 + struct dm_snap_tracked_chunk *c = dm_per_bio_data(bio, sizeof(struct dm_snap_tracked_chunk));
212 220 unsigned long flags;
213 221  
214 222 spin_lock_irqsave(&s->tracked_chunk_lock, flags);
... ... @@ -1568,6 +1576,8 @@
1568 1576 chunk_t chunk;
1569 1577 struct dm_snap_pending_exception *pe = NULL;
1570 1578  
  1579 + init_tracked_chunk(bio);
  1580 +
1571 1581 if (bio->bi_rw & REQ_FLUSH) {
1572 1582 bio->bi_bdev = s->cow->bdev;
1573 1583 return DM_MAPIO_REMAPPED;
... ... @@ -1652,7 +1662,7 @@
1652 1662 }
1653 1663 } else {
1654 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 1668 out_unlock:
1659 1669  
... ... @@ -1681,12 +1691,13 @@
1681 1691 int r = DM_MAPIO_REMAPPED;
1682 1692 chunk_t chunk;
1683 1693  
  1694 + init_tracked_chunk(bio);
  1695 +
1684 1696 if (bio->bi_rw & REQ_FLUSH) {
1685 1697 if (!dm_bio_get_target_request_nr(bio))
1686 1698 bio->bi_bdev = s->origin->bdev;
1687 1699 else
1688 1700 bio->bi_bdev = s->cow->bdev;
1689   - map_context->ptr = NULL;
1690 1701 return DM_MAPIO_REMAPPED;
1691 1702 }
1692 1703  
... ... @@ -1715,7 +1726,7 @@
1715 1726 remap_exception(s, e, bio, chunk);
1716 1727  
1717 1728 if (bio_rw(bio) == WRITE)
1718   - map_context->ptr = track_chunk(s, bio, chunk);
  1729 + track_chunk(s, bio, chunk);
1719 1730 goto out_unlock;
1720 1731 }
1721 1732  
1722 1733  
... ... @@ -1737,10 +1748,9 @@
1737 1748 int error, union map_info *map_context)
1738 1749 {
1739 1750 struct dm_snapshot *s = ti->private;
1740   - struct dm_snap_tracked_chunk *c = map_context->ptr;
1741 1751  
1742   - if (c)
1743   - stop_tracking_chunk(s, c);
  1752 + if (is_bio_tracked(bio))
  1753 + stop_tracking_chunk(s, bio);
1744 1754  
1745 1755 return 0;
1746 1756 }