From patchwork Mon Oct 5 19:02:36 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Snitzer X-Patchwork-Id: 51774 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 n95J2qrL016118 for ; Mon, 5 Oct 2009 19:02:52 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 62C398E088D; Mon, 5 Oct 2009 15:02:51 -0400 (EDT) Received: from int-mx01.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 n95J2mLf009942 for ; Mon, 5 Oct 2009 15:02:48 -0400 Received: from localhost (dhcp-100-18-171.bos.redhat.com [10.16.18.171]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n95J2mHs029881; Mon, 5 Oct 2009 15:02:48 -0400 From: Mike Snitzer To: dm-devel@redhat.com Date: Mon, 5 Oct 2009 15:02:36 -0400 Message-Id: <1254769367-12111-2-git-send-email-snitzer@redhat.com> In-Reply-To: <1254769367-12111-1-git-send-email-snitzer@redhat.com> References: <1254769367-12111-1-git-send-email-snitzer@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-loop: dm-devel@redhat.com Cc: Mikulas Patocka Subject: [dm-devel] [PATCH 01/12] dm-exception-store-merge-methods 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-exception-store.h b/drivers/md/dm-exception-store.h index 5737796..b293595 100644 --- a/drivers/md/dm-exception-store.h +++ b/drivers/md/dm-exception-store.h @@ -79,6 +79,22 @@ struct dm_exception_store_type { void *callback_context); /* + * Returns the last chunk in the pointers. (TODO: -ENOPARSE) + * > 0: the number of consecutive chunks that can + * be copied in one shot. + * == 0: the exception store is empty. + * < 0: error. + */ + int (*prepare_merge) (struct dm_exception_store *store, + chunk_t *old_chunk, chunk_t *new_chunk); + + /* + * Clear the last n exceptions. + * n must be <= the value returned by prepare_merge. + */ + int (*commit_merge) (struct dm_exception_store *store, int n); + + /* * The snapshot is invalid, note this in the metadata. */ void (*drop_snapshot) (struct dm_exception_store *store); diff --git a/drivers/md/dm-snap-persistent.c b/drivers/md/dm-snap-persistent.c index fbcedc3..2523056 100644 --- a/drivers/md/dm-snap-persistent.c +++ b/drivers/md/dm-snap-persistent.c @@ -409,6 +409,15 @@ static void write_exception(struct pstore *ps, e->new_chunk = cpu_to_le64(de->new_chunk); } +static void clear_exception(struct pstore *ps, uint32_t index) +{ + struct disk_exception *e = get_exception(ps, index); + + /* clear it */ + e->old_chunk = 0; + e->new_chunk = 0; +} + /* * Registers the exceptions that are present in the current area. * 'full' is filled in to indicate if the area has been @@ -670,6 +679,63 @@ static void persistent_commit_exception(struct dm_exception_store *store, ps->callback_count = 0; } +static int persistent_prepare_merge(struct dm_exception_store *store, + chunk_t *old_chunk, chunk_t *new_chunk) +{ + int r, i; + struct pstore *ps = get_info(store); + struct disk_exception de; + + if (!ps->current_committed) { + if (!ps->current_area) + return 0; + ps->current_area--; + r = area_io(ps, READ); + if (r < 0) + return r; + ps->current_committed = ps->exceptions_per_area; + } + + read_exception(ps, ps->current_committed - 1, &de); + *old_chunk = de.old_chunk; + *new_chunk = de.new_chunk; + + for (i = 1; i < ps->current_committed; i++) { + read_exception(ps, ps->current_committed - 1 - i, &de); + if (de.old_chunk != *old_chunk - i || + de.new_chunk != *new_chunk - i) + break; + } + + return i; +} + +static int persistent_commit_merge(struct dm_exception_store *store, int n) +{ + int r, i; + struct pstore *ps = get_info(store); + + BUG_ON(n > ps->current_committed); + + for (i = 0; i < n; i++) + clear_exception(ps, ps->current_committed - 1 - i); + + r = area_io(ps, WRITE); + if (r < 0) + return r; + + ps->current_committed -= i; + + /* + * ps->next_free cannot really be reliably decreased here (because of + * misordered chunks), so don't do it. We don't even need it, because + * there is no situation where merging snapshot would become + * non-merging. + */ + + return 0; +} + static void persistent_drop_snapshot(struct dm_exception_store *store) { struct pstore *ps = get_info(store); @@ -739,6 +805,8 @@ static struct dm_exception_store_type _persistent_type = { .read_metadata = persistent_read_metadata, .prepare_exception = persistent_prepare_exception, .commit_exception = persistent_commit_exception, + .prepare_merge = persistent_prepare_merge, + .commit_merge = persistent_commit_merge, .drop_snapshot = persistent_drop_snapshot, .fraction_full = persistent_fraction_full, .status = persistent_status, @@ -752,6 +820,8 @@ static struct dm_exception_store_type _persistent_compat_type = { .read_metadata = persistent_read_metadata, .prepare_exception = persistent_prepare_exception, .commit_exception = persistent_commit_exception, + .prepare_merge = persistent_prepare_merge, + .commit_merge = persistent_commit_merge, .drop_snapshot = persistent_drop_snapshot, .fraction_full = persistent_fraction_full, .status = persistent_status,