Merge target shouldn't allocate new exceptions: - make new method snapshot_merge_map that don't allocate exceptions. - modify __origin_write so that it doesn't allocate exceptions in merging snapshots. - disallow creating merging snapshots with memory-only exception store Signed-off-by: Mikulas Patocka --- drivers/md/dm-snap.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) Index: linux-2.6.28-rc5-devel/drivers/md/dm-snap.c =================================================================== --- linux-2.6.28-rc5-devel.orig/drivers/md/dm-snap.c 2008-11-25 16:11:20.000000000 +0100 +++ linux-2.6.28-rc5-devel/drivers/md/dm-snap.c 2008-11-25 16:11:23.000000000 +0100 @@ -46,6 +46,11 @@ */ #define MIN_IOS 256 +static int snapshot_merge_map(struct dm_target *ti, struct bio *bio, + union map_info *map_context); + +#define is_merge(ti) ((ti)->type->map == snapshot_merge_map) + struct dm_snap_pending_exception { struct dm_snap_exception e; @@ -574,6 +579,12 @@ static int snapshot_ctr(struct dm_target goto bad1; } + if (persistent != 'P' && is_merge(ti)) { + ti->error = "Merging snapshot must be persistent"; + r = -EINVAL; + goto bad1; + } + s = kmalloc(sizeof(*s), GFP_KERNEL); if (s == NULL) { ti->error = "Cannot allocate snapshot context private " @@ -1111,6 +1122,40 @@ static int snapshot_map(struct dm_target return r; } +static int snapshot_merge_map(struct dm_target *ti, struct bio *bio, + union map_info *map_context) +{ + struct dm_snap_exception *e; + struct dm_snapshot *s = ti->private; + int r = DM_MAPIO_REMAPPED; + chunk_t chunk; + + chunk = sector_to_chunk(s, 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 = lookup_exception(&s->complete, chunk); + if (e) { + remap_exception(s, e, bio, chunk); + goto out_unlock; + } + + bio->bi_bdev = s->origin->bdev; + + 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) { @@ -1208,6 +1253,10 @@ static int __origin_write(struct list_he /* Do all the snapshots on this origin */ list_for_each_entry (snap, snapshots, list) { + /* If the snapshot is merging, don't make new exceptions in it + - but in this case no one should be writing to the origin */ + if (is_merge(snap->ti)) continue; + down_write(&snap->lock); /* Only deal with valid and active snapshots */ @@ -1401,7 +1450,7 @@ static struct target_type snapshot_merge .module = THIS_MODULE, .ctr = snapshot_ctr, .dtr = snapshot_dtr, - .map = snapshot_map, + .map = snapshot_merge_map, .end_io = snapshot_end_io, .resume = snapshot_resume, .status = snapshot_status,