Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 176573
b: refs/heads/master
c: 3452c2a
h: refs/heads/master
i:
  176571: 8682f7f
v: v3
  • Loading branch information
Mikulas Patocka authored and Alasdair G Kergon committed Dec 10, 2009
1 parent 6fc4b59 commit 4c178fe
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 515ad66cc4c82f210d726340349c8f7c1ec6b125
refs/heads/master: 3452c2a1eb5b93c1b9fb0d22bd5b07c0cee4dc29
57 changes: 56 additions & 1 deletion trunk/drivers/md/dm-snap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,54 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio,
return r;
}

/*
* A snapshot-merge target behaves like a combination of a snapshot
* target and a snapshot-origin target. It only generates new
* exceptions in other snapshots and not in the one that is being
* merged.
*
* For each chunk, if there is an existing exception, it is used to
* redirect I/O to the cow device. Otherwise I/O is sent to the origin,
* which in turn might generate exceptions in other snapshots.
*/
static int snapshot_merge_map(struct dm_target *ti, struct bio *bio,
union map_info *map_context)
{
struct dm_exception *e;
struct dm_snapshot *s = ti->private;
int r = DM_MAPIO_REMAPPED;
chunk_t chunk;

chunk = sector_to_chunk(s->store, bio->bi_sector);

down_read(&s->lock);

/* Full snapshots are not usable */
if (!s->valid) {
r = -EIO;
goto out_unlock;
}

/* If the block is already remapped - use that */
e = dm_lookup_exception(&s->complete, chunk);
if (e) {
remap_exception(s, e, bio, chunk);
goto out_unlock;
}

bio->bi_bdev = s->origin->bdev;

if (bio_rw(bio) == WRITE) {
up_read(&s->lock);
return do_origin(s->origin, bio);
}

out_unlock:
up_read(&s->lock);

return r;
}

static int snapshot_end_io(struct dm_target *ti, struct bio *bio,
int error, union map_info *map_context)
{
Expand Down Expand Up @@ -1465,6 +1513,13 @@ static int __origin_write(struct list_head *snapshots, sector_t sector,

/* Do all the snapshots on this origin */
list_for_each_entry (snap, snapshots, list) {
/*
* Don't make new exceptions in a merging snapshot
* because it has effectively been deleted
*/
if (dm_target_is_snapshot_merge(snap->ti))
continue;

down_write(&snap->lock);

/* Only deal with valid and active snapshots */
Expand Down Expand Up @@ -1697,7 +1752,7 @@ static struct target_type merge_target = {
.module = THIS_MODULE,
.ctr = snapshot_ctr,
.dtr = snapshot_dtr,
.map = snapshot_map,
.map = snapshot_merge_map,
.end_io = snapshot_end_io,
.postsuspend = snapshot_postsuspend,
.preresume = snapshot_preresume,
Expand Down

0 comments on commit 4c178fe

Please sign in to comment.