diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2008-10-02 18:49:09 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2008-10-02 18:49:09 (GMT) |
commit | 4f7970f9f078942bcb7c1e92f98ed798ccc55025 (patch) | |
tree | d67617b545037294e6a9d62913dbf0fb4f9012ad /src/H5EA.c | |
parent | 8e9bb8af7ccf58e7665a0af4a99c946ad8cb92b2 (diff) | |
download | hdf5-4f7970f9f078942bcb7c1e92f98ed798ccc55025.zip hdf5-4f7970f9f078942bcb7c1e92f98ed798ccc55025.tar.gz hdf5-4f7970f9f078942bcb7c1e92f98ed798ccc55025.tar.bz2 |
[svn-r15755] Description:
Fix some minor problems w/extensible array super blocks and extend
tests.
Tested on:
Mac OS X/32 10.5.5 (amazon) in debug mode
Mac OS X/32 10.5.5 (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/H5EA.c')
-rw-r--r-- | src/H5EA.c | 110 |
1 files changed, 100 insertions, 10 deletions
@@ -325,8 +325,10 @@ H5EA_set(const H5EA_t *ea, hid_t dxpl_id, hsize_t idx, const void *elmt)) /* Local variables */ H5EA_hdr_t *hdr = ea->hdr; /* Header for EA */ H5EA_iblock_t *iblock = NULL; /* Pointer to index block for EA */ + H5EA_sblock_t *sblock = NULL; /* Pointer to super block for EA */ H5EA_dblock_t *dblock = NULL; /* Pointer to data block for EA */ unsigned iblock_cache_flags = H5AC__NO_FLAGS_SET; /* Flags to unprotecting index block */ + unsigned sblock_cache_flags = H5AC__NO_FLAGS_SET; /* Flags to unprotecting super block */ unsigned dblock_cache_flags = H5AC__NO_FLAGS_SET; /* Flags to unprotecting data block */ hbool_t hdr_dirty = FALSE; /* Whether header information changed */ @@ -376,6 +378,7 @@ HDfprintf(stderr, "%s: Index block address is: %a\n", FUNC, hdr->idx_blk_addr); } /* end if */ else { unsigned sblk_idx; /* Which superblock does this index fall in? */ + size_t dblk_idx; /* Data block index */ hsize_t elmt_idx; /* Offset of element in super block */ /* Get super block index where element is located */ @@ -392,8 +395,6 @@ HDfprintf(stderr, "%s: after adjusting for super block elements, elmt_idx = %Hu\ /* Check for data block containing element address in the index block */ if(sblk_idx < iblock->nsblks) { - size_t dblk_idx; /* Data block index */ - #ifdef QAK HDfprintf(stderr, "%s: Element in data block pointed to by address in index block\n", FUNC); #endif /* QAK */ @@ -435,17 +436,25 @@ HDfprintf(stderr, "%s: dblk_idx = %u, iblock->ndblk_addrs = %Zu\n", FUNC, dblk_i dblock_cache_flags |= H5AC__DIRTIED_FLAG; } /* end if */ else { + unsigned sblk_off; /* Offset of super block in index block array of super blocks */ + + /* Calculate offset of super block in index block's array */ + sblk_off = sblk_idx - iblock->nsblks; + /* Check if the super block has been allocated on disk yet */ - if(!H5F_addr_defined(iblock->sblk_addrs[sblk_idx - iblock->nsblks])) { + if(!H5F_addr_defined(iblock->sblk_addrs[sblk_off])) { haddr_t sblk_addr; /* Address of data block created */ /* Create super block */ sblk_addr = H5EA__sblock_create(hdr, dxpl_id, sblk_idx); +#ifdef QAK +HDfprintf(stderr, "%s: New super block address is: %a\n", FUNC, sblk_addr); +#endif /* QAK */ if(!H5F_addr_defined(sblk_addr)) H5E_THROW(H5E_CANTCREATE, "unable to create extensible array super block") /* Set super block address in index block */ - iblock->sblk_addrs[sblk_idx - iblock->nsblks] = sblk_addr; + iblock->sblk_addrs[sblk_off] = sblk_addr; iblock_cache_flags |= H5AC__DIRTIED_FLAG; /* Increment count of actual super blocks created */ @@ -453,8 +462,46 @@ HDfprintf(stderr, "%s: dblk_idx = %u, iblock->ndblk_addrs = %Zu\n", FUNC, dblk_i hdr_dirty = TRUE; } /* end if */ -HDfprintf(stderr, "%s: Super block index %u not supported yet!\n", FUNC, sblk_idx); -HDassert(0 && "Super block index location not supported!"); + /* Protect super block */ + if(NULL == (sblock = H5EA__sblock_protect(hdr, dxpl_id, iblock->sblk_addrs[sblk_off], sblk_idx, H5AC_WRITE))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array super block, address = %llu", (unsigned long_long)iblock->sblk_addrs[sblk_off]) + + /* Compute the data block index in super block */ + dblk_idx = (size_t)(elmt_idx / sblock->dblk_nelmts); +#ifdef QAK +HDfprintf(stderr, "%s: dblk_idx = %u, sblock->ndblks = %Zu\n", FUNC, dblk_idx, sblock->ndblks); +#endif /* QAK */ + HDassert(dblk_idx < sblock->ndblks); + + /* Check if the data block has been allocated on disk yet */ + if(!H5F_addr_defined(sblock->dblk_addrs[dblk_idx])) { + haddr_t dblk_addr; /* Address of data block created */ + + /* Create data block */ + dblk_addr = H5EA__dblock_create(hdr, dxpl_id, sblock->dblk_nelmts); + if(!H5F_addr_defined(dblk_addr)) + H5E_THROW(H5E_CANTCREATE, "unable to create extensible array data block") + + /* Set data block address in index block */ + sblock->dblk_addrs[dblk_idx] = dblk_addr; + sblock_cache_flags |= H5AC__DIRTIED_FLAG; + + /* Increment count of elements "realized" and actual data blocks created */ + hdr->stats.ndata_blks++; + hdr->stats.nelmts += hdr->sblk_info[sblk_idx].dblk_nelmts; + hdr_dirty = TRUE; + } /* end if */ + + /* Protect data block */ + if(NULL == (dblock = H5EA__dblock_protect(hdr, dxpl_id, sblock->dblk_addrs[dblk_idx], sblock->dblk_nelmts, H5AC_WRITE))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array data block, address = %llu", (unsigned long_long)sblock->dblk_addrs[dblk_idx]) + + /* Adjust index to offset in data block */ + elmt_idx %= sblock->dblk_nelmts; + + /* Set element in data block */ + HDmemcpy(((uint8_t *)dblock->elmts) + (hdr->cparam.cls->nat_elmt_size * elmt_idx), elmt, hdr->cparam.cls->nat_elmt_size); + dblock_cache_flags |= H5AC__DIRTIED_FLAG; } /* end else */ } /* end else */ @@ -476,6 +523,8 @@ CATCH /* Release resources */ if(iblock && H5EA__iblock_unprotect(iblock, dxpl_id, iblock_cache_flags) < 0) H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array index block") + if(sblock && H5EA__sblock_unprotect(sblock, dxpl_id, sblock_cache_flags) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array super block") if(dblock && H5EA__dblock_unprotect(dblock, dxpl_id, dblock_cache_flags) < 0) H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array data block") @@ -502,6 +551,7 @@ H5EA_get(const H5EA_t *ea, hid_t dxpl_id, hsize_t idx, void *elmt)) /* Local variables */ H5EA_hdr_t *hdr = ea->hdr; /* Header for EA */ H5EA_iblock_t *iblock = NULL; /* Pointer to index block for EA */ + H5EA_sblock_t *sblock = NULL; /* Pointer to super block for EA */ H5EA_dblock_t *dblock = NULL; /* Pointer to data block for EA */ #ifdef QAK @@ -543,6 +593,7 @@ HDfprintf(stderr, "%s: Index block address is: %a\n", FUNC, hdr->idx_blk_addr); } /* end if */ else { unsigned sblk_idx; /* Which superblock does this index fall in? */ + size_t dblk_idx; /* Data block index */ hsize_t elmt_idx; /* Offset of element in super block */ /* Get super block index where element is located */ @@ -556,8 +607,6 @@ HDfprintf(stderr, "%s: after adjusting for super block elements, elmt_idx = %Hu\ /* Check for data block containing element address in the index block */ if(sblk_idx < iblock->nsblks) { - size_t dblk_idx; /* Data block index */ - #ifdef QAK HDfprintf(stderr, "%s: Element in data block pointed to by address in index block\n", FUNC); #endif /* QAK */ @@ -587,8 +636,47 @@ HDfprintf(stderr, "%s: dblk_idx = %u\n", FUNC, dblk_idx); } /* end else */ } /* end if */ else { -HDfprintf(stderr, "%s: Super block index %Hu not supported yet!\n", FUNC, sblk_idx); -HDassert(0 && "Super block index location not supported!"); + unsigned sblk_off; /* Offset of super block in index block array of super blocks */ + + /* Calculate offset of super block in index block's array */ + sblk_off = sblk_idx - iblock->nsblks; + + /* Check if the super block has been allocated on disk yet */ + if(!H5F_addr_defined(iblock->sblk_addrs[sblk_off])) { + /* Call the class's 'fill' callback */ + if((hdr->cparam.cls->fill)(elmt, (size_t)1) < 0) + H5E_THROW(H5E_CANTSET, "can't set element to class's fill value") + } /* end if */ + else { + /* Protect super block */ + if(NULL == (sblock = H5EA__sblock_protect(hdr, dxpl_id, iblock->sblk_addrs[sblk_off], sblk_idx, H5AC_READ))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array super block, address = %llu", (unsigned long_long)iblock->sblk_addrs[sblk_off]) + + /* Compute the data block index in super block */ + dblk_idx = (size_t)(elmt_idx / sblock->dblk_nelmts); +#ifdef QAK +HDfprintf(stderr, "%s: dblk_idx = %u, sblock->ndblks = %Zu\n", FUNC, dblk_idx, sblock->ndblks); +#endif /* QAK */ + HDassert(dblk_idx < sblock->ndblks); + + /* Check if the data block has been allocated on disk yet */ + if(!H5F_addr_defined(sblock->dblk_addrs[dblk_idx])) { + /* Call the class's 'fill' callback */ + if((hdr->cparam.cls->fill)(elmt, (size_t)1) < 0) + H5E_THROW(H5E_CANTSET, "can't set element to class's fill value") + } /* end if */ + else { + /* Protect data block */ + if(NULL == (dblock = H5EA__dblock_protect(hdr, dxpl_id, sblock->dblk_addrs[dblk_idx], sblock->dblk_nelmts, H5AC_READ))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array data block, address = %llu", (unsigned long_long)sblock->dblk_addrs[dblk_idx]) + + /* Adjust index to offset in data block */ + elmt_idx %= sblock->dblk_nelmts; + + /* Retrieve element from data block */ + HDmemcpy(elmt, ((uint8_t *)dblock->elmts) + (hdr->cparam.cls->nat_elmt_size * elmt_idx), hdr->cparam.cls->nat_elmt_size); + } /* end else */ + } /* end else */ } /* end else */ } /* end else */ } /* end else */ @@ -596,6 +684,8 @@ HDassert(0 && "Super block index location not supported!"); CATCH if(iblock && H5EA__iblock_unprotect(iblock, dxpl_id, H5AC__NO_FLAGS_SET) < 0) H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array index block") + if(sblock && H5EA__sblock_unprotect(sblock, dxpl_id, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array super block") if(dblock && H5EA__dblock_unprotect(dblock, dxpl_id, H5AC__NO_FLAGS_SET) < 0) H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array data block") |