All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

Commit b0d48f57 authored by Mike Hibler's avatar Mike Hibler

Fix bugs in the chunkmap code.

parent 8759fa6c
......@@ -32,6 +32,7 @@
#include "libndz.h"
//#define CHUNK_DEBUG
//#define CHUNKMAP_DEBUG
#ifndef USE_CHUNKMAP
/*
......@@ -73,6 +74,9 @@ ndz_readdata(struct ndz_file *ndz, void *buf, ndz_size_t nsect, ndz_addr_t sect)
ndz_chunkno_t chunkno, lchunkno;
ndz_chunk_t chunk;
ssize_t rbytes, cc;
#ifdef USE_CHUNKMAP
struct ndz_range *prev;
#endif
if (ndz->rangemap == NULL && ndz_readranges(ndz) == NULL) {
fprintf(stderr, "%s could not read sector ranges\n", ndz->fname);
......@@ -157,9 +161,21 @@ ndz_readdata(struct ndz_file *ndz, void *buf, ndz_size_t nsect, ndz_addr_t sect)
#ifdef USE_CHUNKMAP
assert(chunkno < ndz->chunkmapentries);
csect = ndz->chunkmap[chunkno].losect;
crange = ndz_rangemap_lookup(ndz->rangemap, csect, NULL);
assert(crange != NULL);
assert(crange->start == csect);
crange = ndz_rangemap_lookup(ndz->rangemap, csect, &prev);
if (crange == NULL) {
if (prev == NULL)
crange = ndz_rangemap_first(ndz->rangemap);
else
crange = prev->next;
assert(crange != NULL);
}
csect = crange->start;
assert(csect <= ndz->chunkmap[chunkno].hisect);
#ifdef CHUNKMAP_DEBUG
fprintf(stderr, "lookup chunk %u range [%lu-%lu] returns %lu\n",
chunkno, ndz->chunkmap[chunkno].losect,
ndz->chunkmap[chunkno].hisect, csect);
#endif
#else
{
struct fcarg fcarg;
......
......@@ -31,6 +31,8 @@
#include "libndz.h"
//#define CHUNKMAP_DEBUG
struct ndz_file *
ndz_open(const char *name, int forwrite)
{
......@@ -241,9 +243,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]));
#ifdef CHUNKMAP_DEBUG
fprintf(stderr, "allocated chunkmap of %lu bytes for %u chunks\n",
ndz->chunkmapentries * sizeof(ndz->chunkmap[0]),
ndz->chunkmapentries);
#endif
}
#endif
......@@ -253,7 +256,7 @@ ndz_readranges(struct ndz_file *ndz)
*/
for (chunkno = 0; ; chunkno++) {
#ifdef USE_CHUNKMAP
ndz_addr_t clo, chi = 0;
ndz_addr_t clo = 0, chi = 0;
#endif
rv = ndz_readchunkheader(ndz, chunkno, &head);
......@@ -317,6 +320,9 @@ ndz_readranges(struct ndz_file *ndz)
}
ndz->chunkmapentries = chunkno + 1;
}
#ifdef CHUNKMAP_DEBUG
fprintf(stderr, "chunkmap[%u]: [%lu-%lu]\n", chunkno, clo, chi);
#endif
ndz->chunkmap[chunkno].losect = clo;
ndz->chunkmap[chunkno].hisect = chi;
#endif
......
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