/*------------------------------------------------------------------------- * Function: H5HG_load * * Purpose: Loads a global heap collection from disk. * * Return: Success: Ptr to a global heap collection. * * Failure: NULL * * Programmer: Robb Matzke * Friday, March 27, 1998 * *------------------------------------------------------------------------- */ static H5HG_heap_t * H5HG_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * udata1, void UNUSED * udata2) { H5HG_heap_t *heap = NULL; uint8_t *p = NULL; size_t nalloc, need; size_t max_idx = 0; /* The maximum index seen */ H5HG_heap_t *ret_value = NULL; /* Return value */ FUNC_ENTER_NOAPI(H5HG_load, NULL) /* check arguments */ HDassert(f); HDassert(H5F_addr_defined(addr)); HDassert(!udata1); HDassert(!udata2); /* Read the initial 4k page */ if(NULL == (heap = H5FL_CALLOC(H5HG_heap_t))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") heap->addr = addr; if(NULL == (heap->chunk = H5FL_BLK_MALLOC(gheap_chunk, (size_t)H5HG_MINSIZE))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") if(H5F_block_read(f, H5FD_MEM_GHEAP, addr, (size_t)H5HG_MINSIZE, dxpl_id, heap->chunk) < 0) HGOTO_ERROR(H5E_HEAP, H5E_READERROR, NULL, "unable to read global heap collection") /* Magic number */ if(HDmemcmp(heap->chunk, H5HG_MAGIC, (size_t)H5_SIZEOF_MAGIC)) HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, NULL, "bad global heap collection signature") p = heap->chunk + H5_SIZEOF_MAGIC; /* Version */ if(H5HG_VERSION != *p++) HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, NULL, "wrong version number in global heap") /* Reserved */ p += 3; /* Size */ H5F_DECODE_LENGTH(f, p, heap->size); HDassert(heap->size >= H5HG_MINSIZE); /* * If we didn't read enough in the first try, then read the rest of the * collection now. */ if(heap->size > H5HG_MINSIZE) { haddr_t next_addr = addr + (hsize_t)H5HG_MINSIZE; if(NULL == (heap->chunk = H5FL_BLK_REALLOC(gheap_chunk, heap->chunk, heap->size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") if(H5F_block_read(f, H5FD_MEM_GHEAP, next_addr, (heap->size - H5HG_MINSIZE), dxpl_id, heap->chunk + H5HG_MINSIZE) < 0) HGOTO_ERROR(H5E_HEAP, H5E_READERROR, NULL, "unable to read global heap collection") } /* end if */
/*------------------------------------------------------------------------- * Function: H5F_accum_read * * Purpose: Attempts to read some data from the metadata accumulator for * a file into a buffer. * * Note: We can't change (or add to) the metadata accumulator, because * this might be a speculative read and could possibly read raw * data into the metadata accumulator. * * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol * [email protected] * Jan 10 2008 * *------------------------------------------------------------------------- */ herr_t H5F_accum_read(const H5F_t *f, hid_t dxpl_id, H5FD_mem_t type, haddr_t addr, size_t size, void *buf/*out*/) { herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) HDassert(f); HDassert(f->shared); HDassert(buf); /* Check if this information is in the metadata accumulator */ if((f->shared->feature_flags & H5FD_FEAT_ACCUMULATE_METADATA) && type != H5FD_MEM_DRAW) { if(size < H5F_ACCUM_MAX_SIZE) { /* Sanity check */ HDassert(!f->shared->accum.buf || (f->shared->accum.alloc_size >= f->shared->accum.size)); /* Current read adjoins or overlaps with metadata accumulator */ if(H5F_addr_overlap(addr, size, f->shared->accum.loc, f->shared->accum.size) || ((addr + size) == f->shared->accum.loc) || (f->shared->accum.loc + f->shared->accum.size) == addr) { size_t amount_before; /* Amount to read before current accumulator */ haddr_t new_addr; /* New address of the accumulator buffer */ size_t new_size; /* New size of the accumulator buffer */ /* Compute new values for accumulator */ new_addr = MIN(addr, f->shared->accum.loc); new_size = (size_t)(MAX((addr + size), (f->shared->accum.loc + f->shared->accum.size)) - new_addr); /* Check if we need more buffer space */ if(new_size > f->shared->accum.alloc_size) { size_t new_alloc_size; /* New size of accumulator */ /* Adjust the buffer size to be a power of 2 that is large enough to hold data */ new_alloc_size = (size_t)1 << (1 + H5V_log2_gen((uint64_t)(new_size - 1))); /* Reallocate the metadata accumulator buffer */ if(NULL == (f->shared->accum.buf = H5FL_BLK_REALLOC(meta_accum, f->shared->accum.buf, new_alloc_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate metadata accumulator buffer") /* Note the new buffer size */ f->shared->accum.alloc_size = new_alloc_size; #ifdef H5_CLEAR_MEMORY HDmemset(f->shared->accum.buf + f->shared->accum.size, 0, (f->shared->accum.alloc_size - f->shared->accum.size)); #endif /* H5_CLEAR_MEMORY */ } /* end if */ /* Read the part before the metadata accumulator */ if(addr < f->shared->accum.loc) { /* Set the amount to read */ H5_ASSIGN_OVERFLOW(amount_before, (f->shared->accum.loc - addr), hsize_t, size_t); /* Make room for the metadata to read in */ HDmemmove(f->shared->accum.buf + amount_before, f->shared->accum.buf, f->shared->accum.size); /* Adjust dirty region tracking info, if present */ if(f->shared->accum.dirty) f->shared->accum.dirty_off += amount_before; /* Dispatch to driver */ if(H5FD_read(f->shared->lf, dxpl_id, type, addr, amount_before, f->shared->accum.buf) < 0) HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "driver read request failed") } /* end if */ else
/*------------------------------------------------------------------------- * Function: H5F__accum_read * * Purpose: Attempts to read some data from the metadata accumulator for * a file into a buffer. * * Note: We can't change (or add to) the metadata accumulator, because * this might be a speculative read and could possibly read raw * data into the metadata accumulator. * * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol * [email protected] * Jan 10 2008 * *------------------------------------------------------------------------- */ herr_t H5F__accum_read(H5F_t *f, H5FD_mem_t map_type, haddr_t addr, size_t size, void *buf/*out*/) { H5FD_t *file; /* File driver pointer */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE /* Sanity checks */ HDassert(f); HDassert(buf); /* Translate to file driver I/O info object */ file = f->shared->lf; /* Check if this information is in the metadata accumulator */ if((f->shared->feature_flags & H5FD_FEAT_ACCUMULATE_METADATA) && map_type != H5FD_MEM_DRAW) { H5F_meta_accum_t *accum; /* Alias for file's metadata accumulator */ /* Set up alias for file's metadata accumulator info */ accum = &f->shared->accum; if(size < H5F_ACCUM_MAX_SIZE) { /* Sanity check */ HDassert(!accum->buf || (accum->alloc_size >= accum->size)); /* Current read adjoins or overlaps with metadata accumulator */ if(H5F_addr_overlap(addr, size, accum->loc, accum->size) || ((addr + size) == accum->loc) || (accum->loc + accum->size) == addr) { size_t amount_before; /* Amount to read before current accumulator */ haddr_t new_addr; /* New address of the accumulator buffer */ size_t new_size; /* New size of the accumulator buffer */ /* Compute new values for accumulator */ new_addr = MIN(addr, accum->loc); new_size = (size_t)(MAX((addr + size), (accum->loc + accum->size)) - new_addr); /* Check if we need more buffer space */ if(new_size > accum->alloc_size) { size_t new_alloc_size; /* New size of accumulator */ /* Adjust the buffer size to be a power of 2 that is large enough to hold data */ new_alloc_size = (size_t)1 << (1 + H5VM_log2_gen((uint64_t)(new_size - 1))); /* Reallocate the metadata accumulator buffer */ if(NULL == (accum->buf = H5FL_BLK_REALLOC(meta_accum, accum->buf, new_alloc_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate metadata accumulator buffer") /* Note the new buffer size */ accum->alloc_size = new_alloc_size; /* Clear the memory */ HDmemset(accum->buf + accum->size, 0, (accum->alloc_size - accum->size)); } /* end if */ /* Read the part before the metadata accumulator */ if(addr < accum->loc) { /* Set the amount to read */ H5_CHECKED_ASSIGN(amount_before, size_t, (accum->loc - addr), hsize_t); /* Make room for the metadata to read in */ HDmemmove(accum->buf + amount_before, accum->buf, accum->size); /* Adjust dirty region tracking info, if present */ if(accum->dirty) accum->dirty_off += amount_before; /* Dispatch to driver */ if(H5FD_read(file, map_type, addr, amount_before, accum->buf) < 0) HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "driver read request failed") } /* end if */