Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756122AbZKTU3t (ORCPT ); Fri, 20 Nov 2009 15:29:49 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754160AbZKTU3s (ORCPT ); Fri, 20 Nov 2009 15:29:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32325 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755928AbZKTU1x (ORCPT ); Fri, 20 Nov 2009 15:27:53 -0500 From: Mike Snitzer To: dm-devel@redhat.com Cc: linux-kernel@vger.kernel.org, Mikulas Patocka Subject: [PATCH v4 06/13] dm snapshot: merge target should not allocate new exceptions Date: Fri, 20 Nov 2009 15:27:46 -0500 Message-Id: <1258748873-24185-7-git-send-email-snitzer@redhat.com> In-Reply-To: <1258748873-24185-1-git-send-email-snitzer@redhat.com> References: <1258748873-24185-1-git-send-email-snitzer@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3212 Lines: 109 From: Mikulas Patocka The snapshot-merge target should not allocate new exceptions because the intent is to merge all of its exceptions as quickly and safely as possible. Introduce new method, snapshot_merge_map(), that won't allocate exceptions. Modify __origin_write() so that it doesn't allocate exceptions in merging snapshots. If a write request to a merging snapshot device is to be dispatched directly to the origin (because the chunk is not remapped or was already merged), snapshot_merge_map() must make exceptions in other snapshots. Signed-off-by: Mikulas Patocka Signed-off-by: Mike Snitzer --- drivers/md/dm-snap.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 48 insertions(+), 1 deletions(-) diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c index e8a1107..b8838e7 100644 --- a/drivers/md/dm-snap.c +++ b/drivers/md/dm-snap.c @@ -127,6 +127,11 @@ static int bdev_equal(struct block_device *lhs, struct block_device *rhs) return lhs == rhs; } +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_exception e; @@ -1292,6 +1297,44 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio, return r; } +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_write(&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) { @@ -1442,6 +1485,10 @@ static int __origin_write(struct list_head *snapshots, /* Do all the snapshots on this origin */ list_for_each_entry (snap, snapshots, list) { + /* Don't make new exceptions in a merging snapshot */ + if (is_merge(snap->ti)) + continue; + down_write(&snap->lock); /* Only deal with valid and active snapshots */ @@ -1670,7 +1717,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, -- 1.6.5.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/