From patchwork Fri Dec 4 02:23:46 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Snitzer X-Patchwork-Id: 64748 X-Patchwork-Delegate: agk@redhat.com Received: from hormel.redhat.com (hormel1.redhat.com [209.132.177.33]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nB42O2IR005294 for ; Fri, 4 Dec 2009 02:24:02 GMT Received: from listman.util.phx.redhat.com (listman.util.phx.redhat.com [10.8.4.110]) by hormel.redhat.com (Postfix) with ESMTP id 3D20D61C206; Thu, 3 Dec 2009 21:24:02 -0500 (EST) Received: from int-mx05.intmail.prod.int.phx2.redhat.com (nat-pool.util.phx.redhat.com [10.8.5.200]) by listman.util.phx.redhat.com (8.13.1/8.13.1) with ESMTP id nB42NwmN028067 for ; Thu, 3 Dec 2009 21:23:58 -0500 Received: from localhost (dhcp-100-19-150.bos.redhat.com [10.16.19.150]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nB42NvZe014945; Thu, 3 Dec 2009 21:23:58 -0500 From: Mike Snitzer To: dm-devel@redhat.com Date: Thu, 3 Dec 2009 21:23:46 -0500 Message-Id: <1259893434-10792-6-git-send-email-snitzer@redhat.com> In-Reply-To: <1259893434-10792-1-git-send-email-snitzer@redhat.com> References: <1259893434-10792-1-git-send-email-snitzer@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-loop: dm-devel@redhat.com Cc: Mikulas Patocka Subject: [dm-devel] [PATCH v5 05/13] dm snapshot: merge target should not allocate new exceptions X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.5 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c index 15c29a5..c232460 100644 --- a/drivers/md/dm-snap.c +++ b/drivers/md/dm-snap.c @@ -127,6 +127,10 @@ static int bdev_equal(struct block_device *lhs, struct block_device *rhs) return lhs == rhs; } +static const char merge_target_name[] = "snapshot-merge"; + +#define is_merge(ti) ((ti)->type->name == merge_target_name) + struct dm_snap_pending_exception { struct dm_exception e; @@ -1294,6 +1298,53 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio, return r; } +/* + * I/O to a merging snapshot will be: + * - submitted to the origin: if there is no remapped chunk + * - submitted to the snapshot: if there is a remapped chunk + * + * 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() will make 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) { @@ -1446,6 +1497,13 @@ 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 + * because it has effectively been deleted + */ + if (is_merge(snap->ti)) + continue; + down_write(&snap->lock); /* Only deal with valid and active snapshots */ @@ -1669,12 +1727,12 @@ static struct target_type snapshot_target = { }; static struct target_type merge_target = { - .name = "snapshot-merge", + .name = merge_target_name, .version = {1, 9, 0}, .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,