From patchwork Wed Mar 25 21:36:46 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonthan Brassow X-Patchwork-Id: 14430 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 n2PLansc004990 for ; Wed, 25 Mar 2009 21:36:49 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 F0B0161A1EF; Wed, 25 Mar 2009 17:36:49 -0400 (EDT) Received: from int-mx2.corp.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 n2PLamms027660 for ; Wed, 25 Mar 2009 17:36:48 -0400 Received: from hydrogen.msp.redhat.com (hydrogen.msp.redhat.com [10.15.80.1]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n2PLafAW014304 for ; Wed, 25 Mar 2009 17:36:41 -0400 Received: from hydrogen.msp.redhat.com (localhost.localdomain [127.0.0.1]) by hydrogen.msp.redhat.com (8.14.1/8.14.1) with ESMTP id n2PLak9v021953 for ; Wed, 25 Mar 2009 16:36:46 -0500 Received: (from jbrassow@localhost) by hydrogen.msp.redhat.com (8.14.1/8.14.1/Submit) id n2PLakNw021952 for dm-devel@redhat.com; Wed, 25 Mar 2009 16:36:46 -0500 Date: Wed, 25 Mar 2009 16:36:46 -0500 From: Jonathan Brassow Message-Id: <200903252136.n2PLakNw021952@hydrogen.msp.redhat.com> To: dm-devel@redhat.com X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 X-loop: dm-devel@redhat.com Subject: [dm-devel] [PATCH 19 of 33] DM Exception Store: add lookup_exception to API 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 Patch name: dm-exception-store-add-lookup_exception-to-API.patch Now that the exception store implementations are capable of caching the exceptions on their own, we need a new function added to the API to allow us to lookup the exceptions. Adding 'lookup_exception' to the exception store API. Signed-off-by: Jonathan Brassow --- dm-devel mailing list dm-devel@redhat.com https://www.redhat.com/mailman/listinfo/dm-devel Index: linux-2.6/drivers/md/dm-exception-store.h =================================================================== --- linux-2.6.orig/drivers/md/dm-exception-store.h +++ linux-2.6/drivers/md/dm-exception-store.h @@ -58,6 +58,18 @@ struct dm_exception_store_type { void *callback_context); /* + * Look up an exception. Common errors include: + * -ENOENT : exception not found + * -EWOULDBLOCK: blocking op required and can_block=0 + * + * If 'new_chunk' is NULL, the caller simply wants to + * know if the exception exists (0) or not (-ENOENT). + */ + int (*lookup_exception) (struct dm_exception_store *store, + chunk_t old, chunk_t *new_chunk, + int can_block); + + /* * The snapshot is invalid, note this in the metadata. */ void (*drop_snapshot) (struct dm_exception_store *store); Index: linux-2.6/drivers/md/dm-snap-persistent.c =================================================================== --- linux-2.6.orig/drivers/md/dm-snap-persistent.c +++ linux-2.6/drivers/md/dm-snap-persistent.c @@ -721,6 +721,23 @@ static void persistent_commit_exception( ps->callback_count = 0; } +static int persistent_lookup_exception(struct dm_exception_store *store, + chunk_t old, chunk_t *new_chunk, + int can_block) +{ + struct pstore *ps = get_info(store); + struct dm_exception *e; + + e = dm_lookup_exception(ps->table, old); + if (!e) + return -ENOENT; + + if (new_chunk) + *new_chunk = e->new_chunk + (old - e->old_chunk); + + return 0; +} + static void persistent_drop_snapshot(struct dm_exception_store *store) { struct pstore *ps = get_info(store); @@ -813,6 +830,7 @@ static struct dm_exception_store_type _p .read_metadata = persistent_read_metadata, .prepare_exception = persistent_prepare_exception, .commit_exception = persistent_commit_exception, + .lookup_exception = persistent_lookup_exception, .drop_snapshot = persistent_drop_snapshot, .fraction_full = persistent_fraction_full, .status = persistent_status, @@ -827,6 +845,7 @@ static struct dm_exception_store_type _p .read_metadata = persistent_read_metadata, .prepare_exception = persistent_prepare_exception, .commit_exception = persistent_commit_exception, + .lookup_exception = persistent_lookup_exception, .drop_snapshot = persistent_drop_snapshot, .fraction_full = persistent_fraction_full, .status = persistent_status, Index: linux-2.6/drivers/md/dm-snap-transient.c =================================================================== --- linux-2.6.orig/drivers/md/dm-snap-transient.c +++ linux-2.6/drivers/md/dm-snap-transient.c @@ -94,6 +94,23 @@ static void transient_commit_exception(s callback(callback_context, 1); } +static int transient_lookup_exception(struct dm_exception_store *store, + chunk_t old, chunk_t *new_chunk, + int can_block) +{ + struct transient_c *tc = store->context; + struct dm_exception *e; + + e = dm_lookup_exception(tc->table, old); + if (!e) + return -ENOENT; + + if (new_chunk) + *new_chunk = e->new_chunk + (old - e->old_chunk); + + return 0; +} + static void transient_fraction_full(struct dm_exception_store *store, sector_t *numerator, sector_t *denominator) { @@ -165,6 +182,7 @@ static struct dm_exception_store_type _t .read_metadata = transient_read_metadata, .prepare_exception = transient_prepare_exception, .commit_exception = transient_commit_exception, + .lookup_exception = transient_lookup_exception, .fraction_full = transient_fraction_full, .status = transient_status, }; @@ -178,6 +196,7 @@ static struct dm_exception_store_type _t .read_metadata = transient_read_metadata, .prepare_exception = transient_prepare_exception, .commit_exception = transient_commit_exception, + .lookup_exception = transient_lookup_exception, .fraction_full = transient_fraction_full, .status = transient_status, }; Index: linux-2.6/drivers/md/dm-snap.c =================================================================== --- linux-2.6.orig/drivers/md/dm-snap.c +++ linux-2.6/drivers/md/dm-snap.c @@ -963,15 +963,12 @@ __find_pending_exception(struct dm_snaps return pe; } -static void remap_exception(struct dm_snapshot *s, struct dm_exception *e, - struct bio *bio, chunk_t chunk) +static void remap_exception(struct dm_snapshot *s, struct bio *bio, + chunk_t chunk) { bio->bi_bdev = s->store->cow->bdev; - bio->bi_sector = chunk_to_sector(s->store, - dm_chunk_number(e->new_chunk) + - (chunk - e->old_chunk)) + - (bio->bi_sector & - s->store->chunk_mask); + bio->bi_sector = chunk_to_sector(s->store, dm_chunk_number(chunk)) + + (bio->bi_sector & s->store->chunk_mask); } static int snapshot_map(struct dm_target *ti, struct bio *bio, @@ -979,8 +976,8 @@ static int snapshot_map(struct dm_target { struct dm_exception *e, *tmp_e; struct dm_snapshot *s = ti->private; - int r = DM_MAPIO_REMAPPED; - chunk_t chunk; + int rtn, r = DM_MAPIO_REMAPPED; + chunk_t chunk, new_chunk; struct dm_snap_pending_exception *pe = NULL; chunk = sector_to_chunk(s->store, bio->bi_sector); @@ -1000,13 +997,20 @@ static int snapshot_map(struct dm_target } /* If the block is already remapped - use that, else remap it */ - e = dm_lookup_exception(s->complete, chunk); - if (e) { - remap_exception(s, e, bio, chunk); + rtn = s->store->type->lookup_exception(s->store, chunk, &new_chunk, 0); + if (!rtn) { + remap_exception(s, bio, new_chunk); goto out_unlock; } /* + * Could be -EWOULDBLOCK, but we don't handle that yet + * and there are currently no exception store + * implementations that would require us to. + */ + BUG_ON(rtn != -ENOENT); + + /* * Write to snapshot - higher level takes care of RW/RO * flags so we should only get this if we are * writeable. @@ -1025,11 +1029,11 @@ static int snapshot_map(struct dm_target r = -EIO; goto out_unlock; } - - e = dm_lookup_exception(&s->complete, chunk); - if (e) { + rtn = s->store->type->lookup_exception(s->store, chunk, + &new_chunk, 0); + if (!rtn) { dm_free_exception(s->pending, &pe->e); - remap_exception(s, e, bio, chunk); + remap_exception(s, bio, new_chunk); goto out_unlock; } @@ -1041,7 +1045,7 @@ static int snapshot_map(struct dm_target } } - remap_exception(s, &pe->e, bio, chunk); + remap_exception(s, bio, pe->e.new_chunk); bio_list_add(&pe->snapshot_bios, bio); r = DM_MAPIO_SUBMITTED; @@ -1142,7 +1146,7 @@ static int snapshot_status(struct dm_tar *---------------------------------------------------------------*/ static int __origin_write(struct list_head *snapshots, struct bio *bio) { - int r = DM_MAPIO_REMAPPED, first = 0; + int rtn, r = DM_MAPIO_REMAPPED, first = 0; struct dm_snapshot *snap; struct dm_exception *e, *tmp_e; struct dm_snap_pending_exception *pe, *next_pe, *primary_pe = NULL; @@ -1176,10 +1180,18 @@ static int __origin_write(struct list_he * ref_count is initialised to 1 so pending_complete() * won't destroy the primary_pe while we're inside this loop. */ - e = dm_lookup_exception(snap->complete, chunk); - if (e) + rtn = snap->store->type->lookup_exception(snap->store, chunk, + NULL, 0); + if (!rtn) goto next_snapshot; + /* + * 'rtn' could be -EWOULDBLOCK, but we don't handle that yet + * and there are currently no exception store implementations + * that would require us to. + */ + BUG_ON(rtn != -ENOENT); + pe = __lookup_pending_exception(snap, chunk); if (!pe) { up_write(&snap->lock); @@ -1193,8 +1205,10 @@ static int __origin_write(struct list_he goto next_snapshot; } - e = dm_lookup_exception(&snap->complete, chunk); - if (e) { + rtn = snap->store->type->lookup_exception(snap->store, + chunk, NULL, + 0); + if (!rtn) { dm_free_exception(snap->pending, &pe->e); goto next_snapshot; }