diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2008-09-22 15:22:03 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2008-09-22 15:22:03 (GMT) |
commit | 00bd6ae9c27f520b4badbe0698ea1a1e1044f305 (patch) | |
tree | 0ca87cd3b1254b3faa9fbcbea2e76d4248f9ffb9 /src/H5EAiblock.c | |
parent | 0402e025278dbd5ac463ce27805231d5302def1d (diff) | |
download | hdf5-00bd6ae9c27f520b4badbe0698ea1a1e1044f305.zip hdf5-00bd6ae9c27f520b4badbe0698ea1a1e1044f305.tar.gz hdf5-00bd6ae9c27f520b4badbe0698ea1a1e1044f305.tar.bz2 |
[svn-r15674] Description:
Add base support for extensible array "data blocks" to code, tests and
h5debug.
Tested on:
Mac OS X/32 10.5.4 (amazon) in debug mode
Mac OS X/32 10.5.4 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/Intel compilers w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
Diffstat (limited to 'src/H5EAiblock.c')
-rw-r--r-- | src/H5EAiblock.c | 179 |
1 files changed, 159 insertions, 20 deletions
diff --git a/src/H5EAiblock.c b/src/H5EAiblock.c index 2e924a9..bf3fac4 100644 --- a/src/H5EAiblock.c +++ b/src/H5EAiblock.c @@ -42,7 +42,9 @@ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ #include "H5EApkg.h" /* Extensible Arrays */ +#include "H5FLprivate.h" /* Free Lists */ #include "H5MFprivate.h" /* File memory management */ +#include "H5Vprivate.h" /* Vectors and arrays */ /****************/ @@ -80,17 +82,20 @@ /*******************/ /* Declare a free list to manage the H5EA_iblock_t struct */ -H5FL_DEFINE(H5EA_iblock_t); +H5FL_DEFINE_STATIC(H5EA_iblock_t); /* Declare a free list to manage the index block elements */ -H5FL_BLK_DEFINE(elmt_buf); +H5FL_BLK_DEFINE_STATIC(idx_blk_elmt_buf); + +/* Declare a free list to manage the haddr_t sequence information */ +H5FL_SEQ_DEFINE_STATIC(haddr_t); /*------------------------------------------------------------------------- * Function: H5EA__iblock_alloc * - * Purpose: Allocate shared extensible array index block + * Purpose: Allocate extensible array index block * * Return: Non-NULL pointer to index block on success/NULL on failure * @@ -117,17 +122,42 @@ H5EA__iblock_alloc(H5EA_hdr_t *hdr)) /* Set non-zero internal fields */ iblock->addr = HADDR_UNDEF; + /* Compute information */ + iblock->nsblks = 2 * H5V_log2_of2((uint32_t)hdr->sup_blk_min_data_ptrs); + iblock->ndblk_addrs = 2 * ((size_t)hdr->sup_blk_min_data_ptrs - 1); + iblock->nsblk_addrs = hdr->nsblks - iblock->nsblks; +#ifdef QAK +HDfprintf(stderr, "%s: iblock->nsblks = %u\n", FUNC, iblock->nsblks); +HDfprintf(stderr, "%s: iblock->ndblk_addrs = %Zu\n", FUNC, iblock->ndblk_addrs); +HDfprintf(stderr, "%s: iblock->nsblk_addrs = %Zu\n", FUNC, iblock->nsblk_addrs); +#endif /* QAK */ + /* Allocate buffer for elements in index block */ if(hdr->idx_blk_elmts > 0) - if(NULL == (iblock->elmts = H5FL_BLK_MALLOC(elmt_buf, (size_t)(hdr->idx_blk_elmts * hdr->cls->nat_elmt_size)))) + if(NULL == (iblock->elmts = H5FL_BLK_MALLOC(idx_blk_elmt_buf, (size_t)(hdr->idx_blk_elmts * hdr->cls->nat_elmt_size)))) H5E_THROW(H5E_CANTALLOC, "memory allocation failed for index block data element buffer") + /* Allocate buffer for data block addresses in index block */ + if(iblock->ndblk_addrs > 0) + if(NULL == (iblock->dblk_addrs = H5FL_SEQ_MALLOC(haddr_t, iblock->ndblk_addrs))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for index block data block addresses") + + /* Allocate buffer for super block addresses in index block */ + if(iblock->nsblk_addrs > 0) + if(NULL == (iblock->sblk_addrs = H5FL_SEQ_MALLOC(haddr_t, iblock->nsblk_addrs))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for index block super block addresses") + + /* Share common array information */ + iblock->hdr = hdr; + if(H5EA__hdr_incr(hdr) < 0) + H5E_THROW(H5E_CANTINC, "can't increment reference count on shared array header") + /* Set the return value */ ret_value = iblock; CATCH if(!ret_value) - if(iblock && H5EA__cache_iblock_dest(hdr->f, iblock) < 0) + if(iblock && H5EA__iblock_dest(hdr->f, iblock) < 0) H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array index block") END_FUNC(PKG) /* end H5EA__iblock_alloc() */ @@ -154,7 +184,7 @@ H5EA__iblock_create(H5EA_hdr_t *hdr, hid_t dxpl_id)) H5EA_iblock_t *iblock = NULL; /* Extensible array index block */ #ifdef QAK -HDfprintf(stderr, "%s: Called\n", __func__); +HDfprintf(stderr, "%s: Called\n", FUNC); #endif /* QAK */ /* Sanity check */ @@ -164,21 +194,16 @@ HDfprintf(stderr, "%s: Called\n", __func__); if(NULL == (iblock = H5EA__iblock_alloc(hdr))) H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array index block") - /* Set size of header on disk */ - iblock->size = H5EA_IBLOCK_SIZE(hdr); + /* Set size of index block on disk */ + iblock->size = H5EA_IBLOCK_SIZE(iblock); #ifdef QAK -HDfprintf(stderr, "%s: iblock->size = %Zu\n", __func__, iblock->size); +HDfprintf(stderr, "%s: iblock->size = %Zu\n", FUNC, iblock->size); #endif /* QAK */ /* Allocate space for the index block on disk */ if(HADDR_UNDEF == (iblock->addr = H5MF_alloc(hdr->f, H5FD_MEM_EARRAY_IBLOCK, dxpl_id, iblock->size))) H5E_THROW(H5E_CANTALLOC, "file allocation failed for extensible array index block") - /* Share common array information */ - iblock->hdr = hdr; - if(H5EA__hdr_incr(hdr) < 0) - H5E_THROW(H5E_CANTINC, "can't increment reference count on shared array header") - /* Clear any elements in index block to fill value */ if(hdr->idx_blk_elmts > 0) { /* Call the class's 'fill' callback */ @@ -186,6 +211,22 @@ HDfprintf(stderr, "%s: iblock->size = %Zu\n", __func__, iblock->size); H5E_THROW(H5E_CANTSET, "can't set extensible array index block elements to class's fill value") } /* end if */ + /* Reset any data block addresses in the index block */ + if(iblock->ndblk_addrs > 0) { + haddr_t tmp_addr = HADDR_UNDEF; /* Address value to fill data block addresses with */ + + /* Set all the data block addresses to "undefined" address value */ + H5V_array_fill(iblock->dblk_addrs, &tmp_addr, sizeof(haddr_t), iblock->ndblk_addrs); + } /* end if */ + + /* Reset any super block addresses in the index block */ + if(iblock->nsblk_addrs > 0) { + haddr_t tmp_addr = HADDR_UNDEF; /* Address value to fill super block addresses with */ + + /* Set all the super block addresses to "undefined" address value */ + H5V_array_fill(iblock->sblk_addrs, &tmp_addr, sizeof(haddr_t), iblock->nsblk_addrs); + } /* end if */ + /* Cache the new extensible array index block */ if(H5AC_set(hdr->f, dxpl_id, H5AC_EARRAY_IBLOCK, iblock->addr, iblock, H5AC__NO_FLAGS_SET) < 0) H5E_THROW(H5E_CANTINSERT, "can't add extensible array index block to cache") @@ -201,7 +242,7 @@ CATCH H5E_THROW(H5E_CANTFREE, "unable to release extensible array index block") /* Destroy index block */ - if(H5EA__cache_iblock_dest(hdr->f, iblock) < 0) + if(H5EA__iblock_dest(hdr->f, iblock) < 0) H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array index block") } /* end if */ @@ -228,7 +269,7 @@ H5EA__iblock_protect(H5EA_hdr_t *hdr, hid_t dxpl_id, H5AC_protect_t rw)) /* Local variables */ #ifdef QAK -HDfprintf(stderr, "%s: Called\n", __func__); +HDfprintf(stderr, "%s: Called\n", FUNC); #endif /* QAK */ /* Sanity check */ @@ -248,7 +289,7 @@ END_FUNC(PKG) /* end H5EA__iblock_protect() */ * * Purpose: Convenience wrapper around unprotecting extensible array index block * - * Return: SUCCEED/FAIL + * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol * koziol@hdfgroup.org @@ -263,7 +304,7 @@ H5EA__iblock_unprotect(H5EA_iblock_t *iblock, hid_t dxpl_id, unsigned cache_flag /* Local variables */ #ifdef QAK -HDfprintf(stderr, "%s: Called\n", __func__); +HDfprintf(stderr, "%s: Called\n", FUNC); #endif /* QAK */ /* Sanity check */ @@ -299,7 +340,7 @@ H5EA__iblock_delete(H5EA_hdr_t *hdr, hid_t dxpl_id)) H5EA_iblock_t *iblock = NULL; /* Pointer to index block */ #ifdef QAK -HDfprintf(stderr, "%s: Called\n", __func__); +HDfprintf(stderr, "%s: Called\n", FUNC); #endif /* QAK */ /* Sanity check */ @@ -310,7 +351,47 @@ HDfprintf(stderr, "%s: Called\n", __func__); if(NULL == (iblock = H5EA__iblock_protect(hdr, dxpl_id, H5AC_WRITE))) H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array index block, address = %llu", (unsigned long_long)hdr->idx_blk_addr) - /* Iterate over data blocks & super blocks (not yet) */ + /* Check for index block having data block pointers */ + if(iblock->ndblk_addrs > 0) { + unsigned sblk_idx; /* Current super block index */ + unsigned dblk_idx; /* Current data block index w/in super block */ + size_t u; /* Local index variable */ + + /* Iterate over data blocks */ + sblk_idx = dblk_idx = 0; + for(u = 0; u < iblock->ndblk_addrs; u++) { + /* Check for data block existing */ + if(H5F_addr_defined(iblock->dblk_addrs[u])) { + /* Delete data block */ + if(H5EA__dblock_delete(hdr, dxpl_id, iblock->dblk_addrs[u], hdr->sblk_info[sblk_idx].dblk_nelmts) < 0) + H5E_THROW(H5E_CANTDELETE, "unable to delete extensible array data block") + iblock->dblk_addrs[u] = HADDR_UNDEF; + } /* end if */ + + /* Advance to next data block w/in super block */ + dblk_idx++; + + /* Check for moving to next super block */ + if(dblk_idx >= hdr->sblk_info[sblk_idx].ndblks) { + sblk_idx++; + dblk_idx = 0; + } /* end if */ + } /* end for */ + } /* end if */ + + /* Check for index block having data block pointers (not yet) */ + if(iblock->nsblk_addrs > 0) { + size_t u; /* Local index variable */ + + /* Iterate over super blocks */ + for(u = 0; u < iblock->nsblk_addrs; u++) { + /* Check for data block existing */ + if(H5F_addr_defined(iblock->sblk_addrs[u])) { +HDfprintf(stderr, "%s: Deleting super blocks not supported yet!\n", FUNC); +HDassert(0 && "Deleting super blocks not supported!"); + } /* end if */ + } /* end for */ + } /* end if */ /* Release index block's disk space */ if(H5MF_xfree(hdr->f, H5FD_MEM_EARRAY_IBLOCK, dxpl_id, hdr->idx_blk_addr, (hsize_t)iblock->size) < 0) @@ -323,3 +404,61 @@ CATCH END_FUNC(PKG) /* end H5EA__iblock_delete() */ + +/*------------------------------------------------------------------------- + * Function: H5EA__iblock_dest + * + * Purpose: Destroys an extensible array index block in memory. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Quincey Koziol + * koziol@hdfgroup.org + * Sep 11 2008 + * + *------------------------------------------------------------------------- + */ +/* ARGSUSED */ +BEGIN_FUNC(PKG, ERR, +herr_t, SUCCEED, FAIL, +H5EA__iblock_dest(H5F_t *f, H5EA_iblock_t *iblock)) + + /* Sanity check */ + HDassert(iblock); + HDassert(iblock->rc == 0); + + /* Set the shared array header's file context for this operation */ + iblock->hdr->f = f; + + /* Check if we've got elements in the index block */ + if(iblock->hdr->idx_blk_elmts > 0) { + /* Free buffer for index block elements */ + HDassert(iblock->elmts); + (void)H5FL_BLK_FREE(idx_blk_elmt_buf, iblock->elmts); + } /* end if */ + + /* Check if we've got data block addresses in the index block */ + if(iblock->ndblk_addrs > 0) { + /* Free buffer for index block data block addresses */ + HDassert(iblock->dblk_addrs); + (void)H5FL_SEQ_FREE(haddr_t, iblock->dblk_addrs); + } /* end if */ + + /* Check if we've got super block addresses in the index block */ + if(iblock->nsblk_addrs > 0) { + /* Free buffer for index block super block addresses */ + HDassert(iblock->sblk_addrs); + (void)H5FL_SEQ_FREE(haddr_t, iblock->sblk_addrs); + } /* end if */ + + /* Decrement reference count on shared info */ + if(H5EA__hdr_decr(iblock->hdr) < 0) + H5E_THROW(H5E_CANTDEC, "can't decrement reference count on shared array header") + + /* Free the index block itself */ + (void)H5FL_FREE(H5EA_iblock_t, iblock); + +CATCH + +END_FUNC(PKG) /* end H5EA__iblock_dest() */ + |