Commit 18d053da authored by Mike Hibler's avatar Mike Hibler

Turn on CHUNKMAP, track map entries.

parent 6a4f1cab
......@@ -24,7 +24,7 @@
#ifndef _LIBNDZ_H_
#define _LIBNDZ_H_
//#define USE_CHUNKMAP
#define USE_CHUNKMAP
#include "imagehdr.h"
#include "imagehash.h"
......
......@@ -241,8 +241,10 @@ ndz_readranges(struct ndz_file *ndz)
ndz_rangemap_deinit(map);
return NULL;
}
#if 0
fprintf(stderr, "allocated chunkmap of %lu bytes\n",
ndz->chunkmapentries * sizeof(ndz->chunkmap[0]));
#endif
}
#endif
......
......@@ -49,6 +49,7 @@ ndz_rangemap_init(ndz_addr_t lo, ndz_addr_t hi)
map->hiaddr = hi;
map->hint = &map->head.next;
map->gen = 1;
map->entries = 0;
map->sectors = 0;
}
return map;
......@@ -130,6 +131,7 @@ ndz_rangemap_alloc(struct ndz_rangemap *map, ndz_addr_t addr, ndz_size_t size,
prev->end = next->end;
prev->next = next->next;
ndz_range_free(next);
map->entries--;
}
/* if hint currently points to prev, leave it */
if (*map->hint != prev)
......@@ -156,6 +158,7 @@ ndz_rangemap_alloc(struct ndz_rangemap *map, ndz_addr_t addr, ndz_size_t size,
prev->next = range;
map->hint = &prev->next;
map->gen++;
map->entries++;
map->sectors += size;
return 0;
......@@ -214,6 +217,7 @@ ndz_rangemap_dealloc(struct ndz_rangemap *map, ndz_addr_t addr, ndz_size_t size)
if (range->end == eaddr) {
prev->next = range->next;
ndz_range_free(range);
map->entries--;
}
/* otherwise increment start of containing range */
else
......@@ -249,6 +253,7 @@ ndz_rangemap_dealloc(struct ndz_rangemap *map, ndz_addr_t addr, ndz_size_t size)
range->end = addr - 1;
map->hint = &range->next;
map->gen++;
map->entries++;
map->sectors -= size;
return 0;
......@@ -342,6 +347,17 @@ ndz_rangemap_last(struct ndz_rangemap *map)
return range;
}
/*
* Return the number of entries in the map.
*
* Does not affect the map hint.
*/
ndz_size_t
ndz_rangemap_entries(struct ndz_rangemap *map)
{
return map->entries;
}
/*
* Return the number of sectors covered by the map.
*
......@@ -529,8 +545,8 @@ ndz_rangemap_dump(struct ndz_rangemap *map, int summaryonly,
unsigned long elements = 0;
int nrange = 0;
printf("MAP: %p (hint=%p, gen=%lu, sectors=%lu)\n",
map, map->hint, map->gen, map->sectors);
printf("MAP: %p (hint=%p, gen=%lu, entries=%lu, sectors=%lu)\n",
map, map->hint, map->gen, map->entries, map->sectors);
ndz_rangemap_dumpstats(map);
for (range = map->head.next; range; range = range->next) {
if (!summaryonly) {
......@@ -549,7 +565,8 @@ ndz_rangemap_dump(struct ndz_rangemap *map, int summaryonly,
elements += (range->end - range->start + 1);
nrange++;
}
printf("\t%d ranges, %lu elements\n", nrange, elements);
assert(nrange == map->entries);
assert(elements == map->sectors);
}
#ifdef RANGEMAP_TEST
......
......@@ -56,6 +56,7 @@ struct ndz_rangemap {
ndz_addr_t loaddr;
ndz_addr_t hiaddr;
uint64_t gen;
ndz_size_t entries;
ndz_size_t sectors;
#ifdef NDZ_RANGEMAP_STATS
struct ndz_rangemap_stats stats;
......@@ -75,6 +76,7 @@ int ndz_rangemap_iterate(struct ndz_rangemap *map,
void *arg);
struct ndz_range *ndz_rangemap_first(struct ndz_rangemap *map);
struct ndz_range *ndz_rangemap_last(struct ndz_rangemap *map);
ndz_size_t ndz_rangemap_entries(struct ndz_rangemap *map);
ndz_size_t ndz_rangemap_sectors(struct ndz_rangemap *map);
struct ndz_range *ndz_rangemap_lookup(struct ndz_rangemap *map,
ndz_addr_t addr,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment