From patchwork Fri Nov 20 20:27:44 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Snitzer X-Patchwork-Id: 61774 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 nAKKS2o3009388 for ; Fri, 20 Nov 2009 20:28: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 ADB1861A69E; Fri, 20 Nov 2009 15:28:01 -0500 (EST) Received: from int-mx04.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 nAKKRvDY026371 for ; Fri, 20 Nov 2009 15:27:57 -0500 Received: from localhost (dhcp-100-19-150.bos.redhat.com [10.16.19.150]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nAKKRuhR009086; Fri, 20 Nov 2009 15:27:56 -0500 From: Mike Snitzer To: dm-devel@redhat.com Date: Fri, 20 Nov 2009 15:27:44 -0500 Message-Id: <1258748873-24185-5-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> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-loop: dm-devel@redhat.com Cc: Mikulas Patocka , linux-kernel@vger.kernel.org Subject: [dm-devel] [PATCH v4 04/13] dm exception store: snapshot-merge usage accounting 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-persistent.c b/drivers/md/dm-snap-persistent.c index 1f5752e..3cb609b 100644 --- a/drivers/md/dm-snap-persistent.c +++ b/drivers/md/dm-snap-persistent.c @@ -91,6 +91,7 @@ struct pstore { struct dm_exception_store *store; int version; int valid; + int merging; /* 1 if there is merging going on */ uint32_t exceptions_per_area; /* @@ -506,7 +507,20 @@ static void persistent_usage(struct dm_exception_store *store, { struct pstore *ps = get_info(store); - *sectors_allocated = ps->next_free * store->chunk_size; + /* + * Must maintain the fact that DM reports all metadata chunks + * in 'sectors_allocated' + * - preserves the established kernel<->userspace interface + * - snapshot-merge must account for the first two metadata + * chunks in its 'sectors_allocated' + */ + if (!ps->merging) { + *sectors_allocated = ps->next_free * store->chunk_size; + } else { + *sectors_allocated = + (area_location(ps, ps->current_area) - 1 + + ps->current_committed + 2) * store->chunk_size; + } *total_sectors = get_dev_size(dm_snap_cow(store->snap)->bdev); /* @@ -608,6 +622,8 @@ static int persistent_prepare_exception(struct dm_exception_store *store, chunk_t next_free; sector_t size = get_dev_size(dm_snap_cow(store->snap)->bdev); + ps->merging = 0; + /* Is there enough room ? */ if (size < ((ps->next_free + 1) * store->chunk_size)) return -ENOSPC; @@ -696,6 +712,8 @@ static int persistent_prepare_merge(struct dm_exception_store *store, struct pstore *ps = get_info(store); struct disk_exception de; + ps->merging = 1; + if (!ps->current_committed) { if (!ps->current_area) return 0; @@ -767,6 +785,7 @@ static int persistent_ctr(struct dm_exception_store *store, ps->store = store; ps->valid = 1; + ps->merging = 0; ps->version = SNAPSHOT_DISK_VERSION; ps->area = NULL; ps->zero_area = NULL;