diff options
author | Vailin Choi <vchoi@hdfgroup.org> | 2015-06-23 23:06:30 (GMT) |
---|---|---|
committer | Vailin Choi <vchoi@hdfgroup.org> | 2015-06-23 23:06:30 (GMT) |
commit | d043c9c2655b1fbcb1dceb5ee0f29a4c4c47bf4e (patch) | |
tree | ba1d83bbbd949377dde4cc90a46e1dd61735b698 | |
parent | e642d17a4dedabd54819bb09fbd38b13eb985c69 (diff) | |
download | hdf5-d043c9c2655b1fbcb1dceb5ee0f29a4c4c47bf4e.zip hdf5-d043c9c2655b1fbcb1dceb5ee0f29a4c4c47bf4e.tar.gz hdf5-d043c9c2655b1fbcb1dceb5ee0f29a4c4c47bf4e.tar.bz2 |
[svn-r27272] Bring revision #24263 from revise_chksum_retry branch to revise_chunks. h5committested.
-rw-r--r-- | hl/tools/h5watch/h5watchgentest.c | 1 | ||||
-rw-r--r-- | src/H5B2cache.c | 42 | ||||
-rw-r--r-- | src/H5EAcache.c | 56 | ||||
-rw-r--r-- | src/H5F.c | 3 | ||||
-rw-r--r-- | src/H5FAcache.c | 32 | ||||
-rw-r--r-- | src/H5FScache.c | 26 | ||||
-rw-r--r-- | src/H5Fint.c | 24 | ||||
-rw-r--r-- | src/H5Fio.c | 106 | ||||
-rw-r--r-- | src/H5Fpkg.h | 1 | ||||
-rw-r--r-- | src/H5Fprivate.h | 14 | ||||
-rw-r--r-- | src/H5Fquery.c | 23 | ||||
-rw-r--r-- | src/H5Fsuper_cache.c | 135 | ||||
-rw-r--r-- | src/H5HFcache.c | 460 | ||||
-rw-r--r-- | src/H5HFpkg.h | 8 | ||||
-rw-r--r-- | src/H5Ocache.c | 150 | ||||
-rw-r--r-- | src/H5Pfapl.c | 90 | ||||
-rw-r--r-- | src/H5Ppublic.h | 2 | ||||
-rw-r--r-- | src/H5SMcache.c | 27 | ||||
-rw-r--r-- | test/swmr_generator.c | 1 | ||||
-rw-r--r-- | test/testfiles/plist_files/fapl_be | bin | 1462 -> 1481 bytes | |||
-rw-r--r-- | test/testfiles/plist_files/fapl_le | bin | 1462 -> 1481 bytes | |||
-rw-r--r-- | test/testfiles/plist_files/lapl_be | bin | 1562 -> 1581 bytes | |||
-rw-r--r-- | test/testfiles/plist_files/lapl_le | bin | 1562 -> 1581 bytes | |||
-rw-r--r-- | test/tfile.c | 566 |
24 files changed, 1377 insertions, 390 deletions
diff --git a/hl/tools/h5watch/h5watchgentest.c b/hl/tools/h5watch/h5watchgentest.c index df157b4..c4bb7d7 100644 --- a/hl/tools/h5watch/h5watchgentest.c +++ b/hl/tools/h5watch/h5watchgentest.c @@ -20,6 +20,7 @@ #include <string.h> #include <sys/time.h> #include <sys/resource.h> +#include <string.h> /* * WATCH.h5: file with various types of datasets for testing-- diff --git a/src/H5B2cache.c b/src/H5B2cache.c index 0500c37..8d6dccd 100644 --- a/src/H5B2cache.c +++ b/src/H5B2cache.c @@ -187,9 +187,9 @@ H5B2__cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata) if(NULL == (buf = (uint8_t *)H5WB_actual(wb, hdr->hdr_size))) HGOTO_ERROR(H5E_BTREE, H5E_NOSPACE, NULL, "can't get actual buffer") - /* Read header from disk */ - if(H5F_block_read(f, H5FD_MEM_BTREE, addr, hdr->hdr_size, dxpl_id, buf) < 0) - HGOTO_ERROR(H5E_BTREE, H5E_READERROR, NULL, "can't read B-tree header") + /* Read and validate header from disk */ + if(H5F_read_check_metadata(f, H5FD_MEM_BTREE, addr, hdr->hdr_size, hdr->hdr_size, dxpl_id, buf, &computed_chksum) < 0) + HGOTO_ERROR(H5E_BTREE, H5E_BADVALUE, NULL, "incorrect metadata checksum for v2 B-tree header") /* Get temporary pointer to serialized header */ p = buf; @@ -232,10 +232,7 @@ H5B2__cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata) /* Sanity check */ HDassert((size_t)(p - (const uint8_t *)buf) == hdr->hdr_size); - /* Compute checksum on entire header */ - computed_chksum = H5_checksum_metadata(buf, (hdr->hdr_size - H5B2_SIZEOF_CHKSUM), 0); - - /* Verify checksum */ + /* Verify checksum with checksum computed via H5F_read_check_metadata() */ if(stored_chksum != computed_chksum) HGOTO_ERROR(H5E_BTREE, H5E_BADVALUE, NULL, "incorrect metadata checksum for v2 B-tree header") @@ -578,6 +575,7 @@ H5B2__cache_internal_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata) uint32_t stored_chksum; /* Stored metadata checksum value */ uint32_t computed_chksum; /* Computed metadata checksum value */ unsigned u; /* Local index variable */ + uint32_t chk_size; /* Exact size of the node with checksum at the end */ H5B2_internal_t *ret_value; /* Return value */ FUNC_ENTER_STATIC @@ -605,9 +603,12 @@ H5B2__cache_internal_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata) internal->shadowed_next = NULL; internal->shadowed_prev = NULL; - /* Read header from disk */ - if(H5F_block_read(f, H5FD_MEM_BTREE, addr, udata->hdr->node_size, dxpl_id, udata->hdr->page) < 0) - HGOTO_ERROR(H5E_BTREE, H5E_READERROR, NULL, "can't read B-tree internal node") + /* Internal node prefix header + records + child pointer triplets: size with checksum at the end */ + chk_size = H5B2_INT_PREFIX_SIZE + (udata->nrec * udata->hdr->rrec_size) + ((udata->nrec + 1) * H5B2_INT_POINTER_SIZE(udata->hdr, udata->depth)); + + /* Read and validate internal node from disk */ + if(H5F_read_check_metadata(f, H5FD_MEM_BTREE, addr, udata->hdr->node_size, chk_size, dxpl_id, udata->hdr->page, &computed_chksum) < 0) + HGOTO_ERROR(H5E_BTREE, H5E_BADVALUE, NULL, "incorrect metadata checksum for v2 internal node") p = udata->hdr->page; @@ -663,9 +664,6 @@ H5B2__cache_internal_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata) int_node_ptr++; } /* end for */ - /* Compute checksum on internal node */ - computed_chksum = H5_checksum_metadata(udata->hdr->page, (size_t)(p - (const uint8_t *)udata->hdr->page), 0); - /* Metadata checksum */ UINT32DECODE(p, stored_chksum); @@ -945,10 +943,7 @@ done: /*------------------------------------------------------------------------- - * Function: H5B2_cache_internal_size -======= * Function: H5B2__cache_internal_size ->>>>>>> .merge-right.r23988 * * Purpose: Compute the size in bytes of a B-tree internal node * on disk, and return it in *size_ptr. On failure, @@ -1003,6 +998,7 @@ H5B2__cache_leaf_load(H5F_t H5_ATTR_UNUSED *f, hid_t dxpl_id, haddr_t addr, void uint32_t stored_chksum; /* Stored metadata checksum value */ uint32_t computed_chksum; /* Computed metadata checksum value */ unsigned u; /* Local index variable */ + uint32_t chk_size; /* Exact size of the node with checksum at the end */ H5B2_leaf_t *ret_value; /* Return value */ FUNC_ENTER_STATIC @@ -1030,9 +1026,12 @@ H5B2__cache_leaf_load(H5F_t H5_ATTR_UNUSED *f, hid_t dxpl_id, haddr_t addr, void leaf->shadowed_next = NULL; leaf->shadowed_prev = NULL; - /* Read header from disk */ - if(H5F_block_read(udata->f, H5FD_MEM_BTREE, addr, udata->hdr->node_size, dxpl_id, udata->hdr->page) < 0) - HGOTO_ERROR(H5E_BTREE, H5E_READERROR, NULL, "can't read B-tree leaf node") + /* Leaf node prefix header + records: size with checksum at the end */ + chk_size = H5B2_LEAF_PREFIX_SIZE + (udata->nrec * udata->hdr->rrec_size); + + /* Read and validate leaf node from disk */ + if(H5F_read_check_metadata(f, H5FD_MEM_BTREE, addr, udata->hdr->node_size, chk_size, dxpl_id, udata->hdr->page, &computed_chksum) < 0) + HGOTO_ERROR(H5E_BTREE, H5E_BADVALUE, NULL, "incorrect metadata checksum for v2 leaf node") p = udata->hdr->page; @@ -1068,16 +1067,13 @@ H5B2__cache_leaf_load(H5F_t H5_ATTR_UNUSED *f, hid_t dxpl_id, haddr_t addr, void native += udata->hdr->cls->nrec_size; } /* end for */ - /* Compute checksum on leaf node */ - computed_chksum = H5_checksum_metadata(udata->hdr->page, (size_t)(p - (const uint8_t *)udata->hdr->page), 0); - /* Metadata checksum */ UINT32DECODE(p, stored_chksum); /* Sanity check parsing */ HDassert((size_t)(p - (const uint8_t *)udata->hdr->page) <= udata->hdr->node_size); - /* Verify checksum */ + /* Verify checksum with checksum computed via H5F_read_check_metadata() */ if(stored_chksum != computed_chksum) HGOTO_ERROR(H5E_BTREE, H5E_BADVALUE, NULL, "incorrect metadata checksum for v2 leaf node") diff --git a/src/H5EAcache.c b/src/H5EAcache.c index 5168f72..fffa4b3 100644 --- a/src/H5EAcache.c +++ b/src/H5EAcache.c @@ -233,9 +233,9 @@ H5EA__cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *udata)) if(NULL == (buf = (uint8_t *)H5WB_actual(wb, size))) H5E_THROW(H5E_CANTGET, "can't get actual buffer") - /* Read header from disk */ - if(H5F_block_read(f, H5FD_MEM_EARRAY_HDR, addr, size, dxpl_id, buf) < 0) - H5E_THROW(H5E_READERROR, "can't read extensible array header") + /* Read and validate header from disk */ + if(H5F_read_check_metadata(f, H5FD_MEM_EARRAY_HDR, addr, size, size, dxpl_id, buf, &computed_chksum) < 0) + H5E_THROW(H5E_BADVALUE, "incorrect metadata checksum for extensible array header") /* Get temporary pointer to serialized header */ p = buf; @@ -300,17 +300,13 @@ H5EA__cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *udata)) /* (allow for checksum not decoded yet) */ HDassert((size_t)(p - buf) == (size - H5EA_SIZEOF_CHKSUM)); - /* Compute checksum on entire header */ - /* (including the filter information, if present) */ - computed_chksum = H5_checksum_metadata(buf, (size_t)(p - buf), 0); - /* Metadata checksum */ UINT32DECODE(p, stored_chksum); /* Sanity check */ HDassert((size_t)(p - buf) == size); - /* Verify checksum */ + /* Verify checksum with checksum computed via H5F_read_check_metadata() */ if(stored_chksum != computed_chksum) H5E_THROW(H5E_BADVALUE, "incorrect metadata checksum for extensible array header") @@ -602,9 +598,9 @@ H5EA__cache_iblock_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata)) if(NULL == (buf = (uint8_t *)H5WB_actual(wb, size))) H5E_THROW(H5E_CANTGET, "can't get actual buffer") - /* Read index block from disk */ - if(H5F_block_read(f, H5FD_MEM_EARRAY_IBLOCK, addr, size, dxpl_id, buf) < 0) - H5E_THROW(H5E_READERROR, "can't read extensible array index block") + /* Read and validate index block from disk */ + if(H5F_read_check_metadata(f, H5FD_MEM_EARRAY_IBLOCK, addr, size, size, dxpl_id, buf, &computed_chksum) < 0) + H5E_THROW(H5E_BADVALUE, "incorrect metadata checksum for extensible array index block") /* Get temporary pointer to serialized header */ p = buf; @@ -658,16 +654,13 @@ H5EA__cache_iblock_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata)) /* Save the index block's size */ iblock->size = size; - /* Compute checksum on index block */ - computed_chksum = H5_checksum_metadata(buf, (size_t)(p - buf), 0); - /* Metadata checksum */ UINT32DECODE(p, stored_chksum); /* Sanity check */ HDassert((size_t)(p - buf) == iblock->size); - /* Verify checksum */ + /* Verify checksum with checksum computed via H5F_read_check_metadata() */ if(stored_chksum != computed_chksum) H5E_THROW(H5E_BADVALUE, "incorrect metadata checksum for extensible array index block") @@ -1015,9 +1008,9 @@ H5EA__cache_sblock_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata)) if(NULL == (buf = (uint8_t *)H5WB_actual(wb, size))) H5E_THROW(H5E_CANTGET, "can't get actual buffer") - /* Read super block from disk */ - if(H5F_block_read(f, H5FD_MEM_EARRAY_SBLOCK, addr, size, dxpl_id, buf) < 0) - H5E_THROW(H5E_READERROR, "can't read extensible array super block") + /* Read and validate super block from disk */ + if(H5F_read_check_metadata(f, H5FD_MEM_EARRAY_SBLOCK, addr, size, size, dxpl_id, buf, &computed_chksum) < 0) + H5E_THROW(H5E_BADVALUE, "incorrect metadata checksum for extensible array super block") /* Get temporary pointer to serialized header */ p = buf; @@ -1065,16 +1058,13 @@ H5EA__cache_sblock_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata)) /* Save the super block's size */ sblock->size = size; - /* Compute checksum on super block */ - computed_chksum = H5_checksum_metadata(buf, (size_t)(p - buf), 0); - /* Metadata checksum */ UINT32DECODE(p, stored_chksum); /* Sanity check */ HDassert((size_t)(p - buf) == sblock->size); - /* Verify checksum */ + /* Verify checksum with checksum computed via H5F_read_check_metadata() */ if(stored_chksum != computed_chksum) H5E_THROW(H5E_BADVALUE, "incorrect metadata checksum for extensible array super block") @@ -1414,9 +1404,9 @@ H5EA__cache_dblock_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata)) if(NULL == (buf = (uint8_t *)H5WB_actual(wb, size))) H5E_THROW(H5E_CANTGET, "can't get actual buffer") - /* Read data block from disk */ - if(H5F_block_read(f, H5FD_MEM_EARRAY_DBLOCK, addr, size, dxpl_id, buf) < 0) - H5E_THROW(H5E_READERROR, "can't read extensible array data block") + /* Read and validate data block from disk */ + if(H5F_read_check_metadata(f, H5FD_MEM_EARRAY_DBLOCK, addr, size, size, dxpl_id, buf, &computed_chksum) < 0) + H5E_THROW(H5E_BADVALUE, "incorrect metadata checksum for extensible data block") /* Get temporary pointer to serialized header */ p = buf; @@ -1460,16 +1450,13 @@ H5EA__cache_dblock_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata)) /* Set the data block's size */ dblock->size = H5EA_DBLOCK_SIZE(dblock); - /* Compute checksum on data block */ - computed_chksum = H5_checksum_metadata(buf, (size_t)(p - buf), 0); - /* Metadata checksum */ UINT32DECODE(p, stored_chksum); /* Sanity check */ HDassert((size_t)(p - buf) == size); - /* Verify checksum */ + /* Verify checksum with checksum computed via H5F_read_check_metadata() */ if(stored_chksum != computed_chksum) H5E_THROW(H5E_BADVALUE, "incorrect metadata checksum for extensible array data block - # pages = %d", dblock->npages) @@ -1810,9 +1797,9 @@ H5EA__cache_dblk_page_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata)) if(NULL == (buf = (uint8_t *)H5WB_actual(wb, size))) H5E_THROW(H5E_CANTGET, "can't get actual buffer") - /* Read data block page from disk */ - if(H5F_block_read(f, H5FD_MEM_EARRAY_DBLK_PAGE, addr, size, dxpl_id, buf) < 0) - H5E_THROW(H5E_READERROR, "can't read extensible array data block page") + /* Read and validate data block page from disk */ + if(H5F_read_check_metadata(f, H5FD_MEM_EARRAY_DBLK_PAGE, addr, size, size, dxpl_id, buf, &computed_chksum) < 0) + H5E_THROW(H5E_BADVALUE, "incorrect metadata checksum for extensible array data block page") /* Get temporary pointer to serialized header */ p = buf; @@ -1832,16 +1819,13 @@ H5EA__cache_dblk_page_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata)) /* Set the data block page's size */ dblk_page->size = size; - /* Compute checksum on data block */ - computed_chksum = H5_checksum_metadata(buf, (size_t)(p - buf), 0); - /* Metadata checksum */ UINT32DECODE(p, stored_chksum); /* Sanity check */ HDassert((size_t)(p - buf) == dblk_page->size); - /* Verify checksum */ + /* Verify checksum with checksum computed via H5F_read_check_metadata() */ if(stored_chksum != computed_chksum) H5E_THROW(H5E_BADVALUE, "incorrect metadata checksum for extensible array data block page") @@ -847,6 +847,9 @@ H5Freopen(hid_t file_id) if(NULL == (new_file = H5F_new(old_file->shared, 0, H5P_FILE_CREATE_DEFAULT, H5P_FILE_ACCESS_DEFAULT, NULL))) HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to reopen file") + /* Keep old file's read attempts in new file */ + new_file->read_attempts = old_file->read_attempts; + /* Duplicate old file's names */ new_file->open_name = H5MM_xstrdup(old_file->open_name); new_file->actual_name = H5MM_xstrdup(old_file->actual_name); diff --git a/src/H5FAcache.c b/src/H5FAcache.c index 5cf592e..b3be614 100644 --- a/src/H5FAcache.c +++ b/src/H5FAcache.c @@ -196,9 +196,9 @@ H5FA__cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *udata)) if(NULL == (buf = (uint8_t *)H5WB_actual(wb, size))) H5E_THROW(H5E_CANTGET, "can't get actual buffer") - /* Read header from disk */ - if(H5F_block_read(f, H5FD_MEM_FARRAY_HDR, addr, size, dxpl_id, buf) < 0) - H5E_THROW(H5E_READERROR, "can't read fixed array header") + /* Read and vaildate header from disk */ + if(H5F_read_check_metadata(f, H5FD_MEM_FARRAY_HDR, addr, size, size, dxpl_id, buf, &computed_chksum) < 0) + H5E_THROW(H5E_BADVALUE, "incorrect metadata checksum for fixed array header") /* Get temporary pointer to serialized header */ p = buf; @@ -254,17 +254,13 @@ H5FA__cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *udata)) /* (allow for checksum not decoded yet) */ HDassert((size_t)(p - buf) == (size - H5FA_SIZEOF_CHKSUM)); - /* Compute checksum on entire header */ - /* (including the filter information, if present) */ - computed_chksum = H5_checksum_metadata(buf, (size_t)(p - buf), 0); - /* Metadata checksum */ UINT32DECODE(p, stored_chksum); /* Sanity check */ HDassert((size_t)(p - buf) == size); - /* Verify checksum */ + /* Verify checksum with checksum computed via H5F_read_check_metadata() */ if(stored_chksum != computed_chksum) H5E_THROW(H5E_BADVALUE, "incorrect metadata checksum for fixed array header") @@ -544,9 +540,9 @@ H5FA__cache_dblock_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata)) if(NULL == (buf = (uint8_t *)H5WB_actual(wb, size))) H5E_THROW(H5E_CANTGET, "can't get actual buffer") - /* Read data block from disk */ - if(H5F_block_read(f, H5FD_MEM_FARRAY_DBLOCK, addr, size, dxpl_id, buf) < 0) - H5E_THROW(H5E_READERROR, "can't read fixed array data block") + /* Read and validate data block from disk */ + if(H5F_read_check_metadata(f, H5FD_MEM_FARRAY_DBLOCK, addr, size, size, dxpl_id, buf, &computed_chksum) < 0) + H5E_THROW(H5E_BADVALUE, "incorrect metadata checksum for fixed array data block") /* Get temporary pointer to serialized header */ p = buf; @@ -591,16 +587,13 @@ H5FA__cache_dblock_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata)) /* Set the data block's size */ dblock->size = H5FA_DBLOCK_SIZE(dblock); - /* Compute checksum on data block */ - computed_chksum = H5_checksum_metadata(buf, (size_t)(p - buf), 0); - /* Metadata checksum */ UINT32DECODE(p, stored_chksum); /* Sanity check */ HDassert((size_t)(p - buf) == size); - /* Verify checksum */ + /* Verify checksum with checksum computed via H5F_read_check_metadata() */ if(stored_chksum != computed_chksum) H5E_THROW(H5E_BADVALUE, "incorrect metadata checksum for fixed array data block") @@ -937,9 +930,9 @@ H5FA__cache_dblk_page_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata)) if(NULL == (buf = (uint8_t *)H5WB_actual(wb, size))) H5E_THROW(H5E_CANTGET, "can't get actual buffer") - /* Read data block page from disk */ - if(H5F_block_read(f, H5FD_MEM_FARRAY_DBLK_PAGE, addr, size, dxpl_id, buf) < 0) - H5E_THROW(H5E_READERROR, "can't read fixed array data block page") + /* Read and validate data block page from disk */ + if(H5F_read_check_metadata(f, H5FD_MEM_FARRAY_DBLK_PAGE, addr, size, size, dxpl_id, buf, &computed_chksum) < 0) + H5E_THROW(H5E_BADVALUE, "incorrect metadata checksum for fixed array data block page") /* Get temporary pointer to serialized header */ p = buf; @@ -959,9 +952,6 @@ H5FA__cache_dblk_page_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata)) /* Set the data block page's size */ dblk_page->size = size; - /* Compute checksum on data block */ - computed_chksum = H5_checksum_metadata(buf, (size_t)(p - buf), 0); - /* Metadata checksum */ UINT32DECODE(p, stored_chksum); diff --git a/src/H5FScache.c b/src/H5FScache.c index d3605bd..fbc94c3 100644 --- a/src/H5FScache.c +++ b/src/H5FScache.c @@ -182,9 +182,9 @@ H5FS_cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata) if(NULL == (hdr = (uint8_t *)H5WB_actual(wb, fspace->hdr_size))) HGOTO_ERROR(H5E_FSPACE, H5E_NOSPACE, NULL, "can't get actual buffer") - /* Read header from disk */ - if(H5F_block_read(f, H5FD_MEM_FSPACE_HDR, addr, fspace->hdr_size, dxpl_id, hdr) < 0) - HGOTO_ERROR(H5E_FSPACE, H5E_READERROR, NULL, "can't read free space header") + /* Read and validate header from disk */ + if(H5F_read_check_metadata(f, H5FD_MEM_FSPACE_HDR, addr, fspace->hdr_size, fspace->hdr_size, dxpl_id, hdr, &computed_chksum) < 0) + HGOTO_ERROR(H5E_FSPACE, H5E_BADVALUE, NULL, "incorrect metadata checksum for free space header") p = hdr; @@ -241,17 +241,14 @@ H5FS_cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata) /* Allocated size of serialized free space sections */ H5F_DECODE_LENGTH(udata->f, p, fspace->alloc_sect_size); - /* Compute checksum on indirect block */ - computed_chksum = H5_checksum_metadata(hdr, (size_t)(p - (const uint8_t *)hdr), 0); - /* Metadata checksum */ UINT32DECODE(p, stored_chksum); HDassert((size_t)(p - (const uint8_t *)hdr) == fspace->hdr_size); - /* Verify checksum */ + /* Verify checksum with checksum computed via H5F_read_check_metadata() */ if(stored_chksum != computed_chksum) - HGOTO_ERROR(H5E_FSPACE, H5E_BADVALUE, NULL, "incorrect metadata checksum for fractal heap indirect block") + HGOTO_ERROR(H5E_FSPACE, H5E_BADVALUE, NULL, "incorrect metadata checksum for free space header") /* Set return value */ ret_value = fspace; @@ -577,9 +574,9 @@ H5FS_cache_sinfo_load(H5F_t *f, hid_t dxpl_id, haddr_t H5_ATTR_UNUSED addr, void if(NULL == (buf = H5FL_BLK_MALLOC(sect_block, (size_t)udata->fspace->sect_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - /* Read buffer from disk */ - if(H5F_block_read(f, H5FD_MEM_FSPACE_SINFO, udata->fspace->sect_addr, (size_t)udata->fspace->sect_size, dxpl_id, buf) < 0) - HGOTO_ERROR(H5E_FSPACE, H5E_READERROR, NULL, "can't read free space sections") + /* Read and validate free space sections from disk */ + if(H5F_read_check_metadata(f, H5FD_MEM_FSPACE_SINFO, udata->fspace->sect_addr, (size_t)udata->fspace->sect_size, (size_t)udata->fspace->sect_size, dxpl_id, buf, &computed_chksum) < 0) + HGOTO_ERROR(H5E_FSPACE, H5E_BADVALUE, NULL, "incorrect metadata checksum for free space sections") /* Deserialize free sections from buffer available */ p = buf; @@ -671,15 +668,12 @@ H5FS_cache_sinfo_load(H5F_t *f, hid_t dxpl_id, haddr_t H5_ATTR_UNUSED addr, void HDassert(old_tot_space == udata->fspace->tot_space); } /* end if */ - /* Compute checksum on indirect block */ - computed_chksum = H5_checksum_metadata(buf, (size_t)(p - (const uint8_t *)buf), 0); - /* Metadata checksum */ UINT32DECODE(p, stored_chksum); - /* Verify checksum */ + /* Verify checksum with checksum computed via H5F_read_check_metadata() */ if(stored_chksum != computed_chksum) - HGOTO_ERROR(H5E_FSPACE, H5E_BADVALUE, NULL, "incorrect metadata checksum for fractal heap indirect block") + HGOTO_ERROR(H5E_FSPACE, H5E_BADVALUE, NULL, "incorrect metadata checksum for free space sections") /* Sanity check */ HDassert((size_t)(p - (const uint8_t *)buf) == old_sect_size); diff --git a/src/H5Fint.c b/src/H5Fint.c index de28a5d..efa36da 100644 --- a/src/H5Fint.c +++ b/src/H5Fint.c @@ -194,6 +194,8 @@ H5F_get_access_plist(H5F_t *f, hbool_t app_ref) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set 'small data' cache size") if(H5P_set(new_plist, H5F_ACS_LATEST_FORMAT_NAME, &(f->shared->latest_format)) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set 'latest format' flag") + if(H5P_set(new_plist, H5F_ACS_READ_ATTEMPTS_NAME, &(f->read_attempts)) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set 'latest format' flag") if(f->shared->efc) efc_size = H5F_efc_max_nfiles(f->shared->efc); if(H5P_set(new_plist, H5F_ACS_EFC_SIZE_NAME, &efc_size) < 0) @@ -1062,6 +1064,24 @@ H5F_open(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id, shared = file->shared; lf = shared->lf; + file->open_name = H5MM_xstrdup(name); + + /* Get the file access property list, for future queries */ + if(NULL == (a_plist = (H5P_genplist_t *)H5I_object(fapl_id))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not file access property list") + + /* Retrieve the # of read attempts here so that sohm in superblock will get the correct # of attempts */ + if(H5P_get(a_plist, H5F_ACS_READ_ATTEMPTS_NAME, &file->read_attempts) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get the # of read attempts") + + /* When opening file with SWMR access, the # of read attempts is H5_SWMR_READ_ATTEMPTS if not set */ + /* When opening file with non-SWMR access, the # of read attempts is always H5F_READ_ATTEMPTS (set or not set) */ + if(H5F_INTENT(file) & H5F_ACC_SWMR_READ || H5F_INTENT(file) & H5F_ACC_SWMR_WRITE) { + if(!file->read_attempts) + file->read_attempts = H5F_SWMR_READ_ATTEMPTS; + } else + file->read_attempts = H5F_READ_ATTEMPTS; + /* * Read or write the file superblock, depending on whether the file is * empty or not. @@ -1093,10 +1113,6 @@ H5F_open(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id, HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to read root group") } /* end if */ - /* Get the file access property list, for future queries */ - if(NULL == (a_plist = (H5P_genplist_t *)H5I_object(fapl_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not file access property list") - /* * Decide the file close degree. If it's the first time to open the * file, set the degree to access property list value; if it's the diff --git a/src/H5Fio.c b/src/H5Fio.c index 1f187c1..2073983 100644 --- a/src/H5Fio.c +++ b/src/H5Fio.c @@ -259,3 +259,109 @@ done: FUNC_LEAVE_NOAPI(ret_value); } /* end H5F_evict_tagged_metadata */ + +/*------------------------------------------------------------------------- + * Function: H5F_get_checksums + * + * Purpose: Decode checksum stored in the buffer + * Calculate checksum for the data in the buffer + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Vailin Choi; Sept 2013 + * + *------------------------------------------------------------------------- + */ +herr_t +H5F_get_checksums(uint8_t *buf, size_t chk_size, uint32_t *s_chksum/*out*/, uint32_t *c_chksum/*out*/) +{ + uint32_t stored_chksum; /* Stored metadata checksum value */ + uint32_t computed_chksum; /* Computed metadata checksum value */ + const uint8_t *chk_p; /* Pointer into raw data buffer */ + + FUNC_ENTER_NOAPI_NOINIT_NOERR + + /* Check arguments */ + HDassert(buf); + HDassert(chk_size); + + /* Compute checksum for the buffer */ + computed_chksum = H5_checksum_metadata(buf, chk_size - H5_SIZEOF_CHKSUM, 0); + + /* Offset to the checksum in the buffer */ + chk_p = buf + chk_size - H5_SIZEOF_CHKSUM; + + /* Decode the checksum stored in the buffer */ + UINT32DECODE(chk_p, stored_chksum); + + /* Return the stored checksum */ + if(s_chksum) + *s_chksum = stored_chksum; + + /* Return the computed checksum */ + if(c_chksum) + *c_chksum = computed_chksum; + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5F_get_chksums() */ + + +/*------------------------------------------------------------------------- + * Function: H5F_read_check_meatadata + * + * Purpose: Attempts to read and validate a piece of meatadata that has + * checksum as follows: + * a) read the piece of metadata + * b) calculate checksum for the buffer of metadata + * c) decode the checksum stored in the buffer of metadata + d) compare the computed checksum with its stored checksum + * The library will perform (a) to (d) above for "f->read_attempts" + * times or until the checksum comparison in (d) passes. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Vailin Choi; Sept 2013 + * + *------------------------------------------------------------------------- + */ +herr_t +H5F_read_check_metadata(const H5F_t *f, H5FD_mem_t type, haddr_t addr, size_t read_size, size_t chk_size, + hid_t dxpl_id, uint8_t *buf/*out*/, uint32_t *chksum/*out*/) +{ + size_t tries, max_tries; + uint32_t stored_chksum; /* Stored metadata checksum value */ + uint32_t computed_chksum; /* Computed metadata checksum value */ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_NOAPI(FAIL) + + /* Get the # of read attempts */ + max_tries = tries = f->read_attempts; + + do { + /* Read header from disk */ + if(H5F_block_read(f, type, addr, read_size, dxpl_id, buf) < 0) + HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "unable to read metadata") + + /* Get stored and computed checksums */ + H5F_get_checksums(buf, chk_size, &stored_chksum, &computed_chksum); + + /* Verify checksum */ + if(stored_chksum == computed_chksum) + break; + + } while(--tries); + + if(tries == 0) + HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "incorrect metadatda checksum after all read attempts (%u) for %u bytes:c_chksum=%u, s_chkum=%u", + max_tries, chk_size, computed_chksum, stored_chksum) + else if((max_tries - tries + 1) > 1) + HDfprintf(stderr, "%s: SUCCESS after %u attempts; type=%u\n", FUNC, max_tries - tries + 1, type); + + /* Return the computed checksum */ + if(chksum) + *chksum = computed_chksum; + +done: + FUNC_LEAVE_NOAPI(ret_value); +} /* end H5F_read_check_metadata */ diff --git a/src/H5Fpkg.h b/src/H5Fpkg.h index 56c0f7f..5bd5b7f 100644 --- a/src/H5Fpkg.h +++ b/src/H5Fpkg.h @@ -259,6 +259,7 @@ struct H5F_file_t { * to shared H5F_file_t structs. */ struct H5F_t { + unsigned read_attempts; /* The # of reads to try when reading metadata with checksum */ char *open_name; /* Name used to open file */ char *actual_name; /* Actual name of the file, after resolving symlinks, etc. */ char *extpath; /* Path for searching target external link file */ diff --git a/src/H5Fprivate.h b/src/H5Fprivate.h index 185e328..275bb61 100644 --- a/src/H5Fprivate.h +++ b/src/H5Fprivate.h @@ -283,6 +283,7 @@ #define H5F_FILE_ID(F) ((F)->file_id) #define H5F_PARENT(F) ((F)->parent) #define H5F_NMOUNTS(F) ((F)->nmounts) +#define H5F_GET_READ_ATTEMPTS(F) ((F)->read_attempts) #define H5F_DRIVER_ID(F) ((F)->shared->lf->driver_id) #define H5F_GET_FILENO(F,FILENUM) ((FILENUM) = (F)->shared->lf->fileno) #define H5F_HAS_FEATURE(F,FL) ((F)->shared->lf->feature_flags & (FL)) @@ -325,6 +326,7 @@ #define H5F_FILE_ID(F) (H5F_get_file_id(F)) #define H5F_PARENT(F) (H5F_get_parent(F)) #define H5F_NMOUNTS(F) (H5F_get_nmounts(F)) +#define H5F_GET_READ_ATTEMPTS(F) (H5F_get_read_attempts(F)) #define H5F_DRIVER_ID(F) (H5F_get_driver_id(F)) #define H5F_GET_FILENO(F,FILENUM) (H5F_get_fileno((F), &(FILENUM))) #define H5F_HAS_FEATURE(F,FL) (H5F_has_feature(F,FL)) @@ -451,6 +453,7 @@ #define H5F_ACS_MULTI_TYPE_NAME "multi_type" /* Data type in multi file driver */ #define H5F_ACS_LATEST_FORMAT_NAME "latest_format" /* 'Use latest format version' flag */ #define H5F_ACS_WANT_POSIX_FD_NAME "want_posix_fd" /* Internal: query the file descriptor from the core VFD, instead of the memory address */ +#define H5F_ACS_READ_ATTEMPTS_NAME "read_attempts" /* # of read attempts */ #define H5F_ACS_EFC_SIZE_NAME "efc_size" /* Size of external file cache */ #define H5F_ACS_FILE_IMAGE_INFO_NAME "file_image_info" /* struct containing initial file image and callback info */ #define H5F_ACS_CORE_WRITE_TRACKING_FLAG_NAME "core_write_tracking_flag" /* Whether or not core VFD backing store write tracking is enabled */ @@ -501,6 +504,11 @@ /* (all on-disk signatures should be this length) */ #define H5_SIZEOF_MAGIC 4 +#define H5_SIZEOF_CHKSUM 4 + +#define H5F_READ_ATTEMPTS 1 /* Default # of read attempts for non-swmr access */ +#define H5F_SWMR_READ_ATTEMPTS 100 /* Default # of read attempts for swmr access */ + /* v1 B-tree node signature */ #define H5B_MAGIC "TREE" @@ -608,6 +616,7 @@ H5_DLL hid_t H5F_get_file_id(const H5F_t *f); H5_DLL ssize_t H5F_get_file_image(H5F_t *f, void *buf_ptr, size_t buf_len); H5_DLL H5F_t *H5F_get_parent(const H5F_t *f); H5_DLL unsigned H5F_get_nmounts(const H5F_t *f); +H5_DLL unsigned H5F_get_read_attempts(const H5F_t *f); H5_DLL hid_t H5F_get_access_plist(H5F_t *f, hbool_t app_ref); H5_DLL hid_t H5F_get_id(H5F_t *file, hbool_t app_ref); H5_DLL herr_t H5F_get_obj_count(const H5F_t *f, unsigned types, hbool_t app_ref, size_t *obj_id_count_ptr); @@ -666,6 +675,11 @@ H5_DLL herr_t H5F_block_write(const H5F_t *f, H5FD_mem_t type, haddr_t addr, H5_DLL herr_t H5F_flush_tagged_metadata(H5F_t * f, haddr_t tag, hid_t dxpl_id); H5_DLL herr_t H5F_evict_tagged_metadata(H5F_t * f, haddr_t tag, hid_t dxpl_id); +/* Function that read and verify a piece of metadata with checksum */ +H5_DLL herr_t H5F_read_check_metadata(const H5F_t *f, H5FD_mem_t type, haddr_t addr, size_t read_size, size_t chk_size, + hid_t dxpl_id, uint8_t *buf/*out*/, uint32_t *chksum/*out*/); +H5_DLL herr_t H5F_get_checksums(uint8_t *buf, size_t chk_size, uint32_t *s_chksum, uint32_t *c_chksum); + /* Address-related functions */ H5_DLL void H5F_addr_encode(const H5F_t *f, uint8_t **pp, haddr_t addr); H5_DLL void H5F_addr_encode_len(size_t addr_len, uint8_t **pp, haddr_t addr); diff --git a/src/H5Fquery.c b/src/H5Fquery.c index 6290614..69fe193 100644 --- a/src/H5Fquery.c +++ b/src/H5Fquery.c @@ -322,6 +322,29 @@ H5F_get_nmounts(const H5F_t *f) /*------------------------------------------------------------------------- + * Function: H5F_get_read_attempts + * + * Purpose: Retrieve the file's 'read_attempts' value + * + * Return: '# of read attempts' on success/abort on failure (shouldn't fail) + * + * Programmer: Vaili Choi; Sept 2013 + * + *------------------------------------------------------------------------- + */ +unsigned +H5F_get_read_attempts(const H5F_t *f) +{ + /* Use FUNC_ENTER_NOAPI_NOINIT_NOERR here to avoid performance issues */ + FUNC_ENTER_NOAPI_NOINIT_NOERR + + HDassert(f); + + FUNC_LEAVE_NOAPI(f->read_attempts) +} /* end H5F_get_read_attempts() */ + + +/*------------------------------------------------------------------------- * Function: H5F_get_fcpl * * Purpose: Retrieve the value of a file's FCPL. diff --git a/src/H5Fsuper_cache.c b/src/H5Fsuper_cache.c index f61db7b..daa7145 100644 --- a/src/H5Fsuper_cache.c +++ b/src/H5Fsuper_cache.c @@ -140,7 +140,11 @@ H5F_sblock_load(H5F_t *f, hid_t dxpl_id, haddr_t H5_ATTR_UNUSED addr, void *_uda uint8_t *p; /* Temporary pointer into encoding buffer */ unsigned super_vers; /* Superblock version */ hbool_t *dirtied = (hbool_t *)_udata; /* Set up dirtied out value */ - H5F_super_t *ret_value; /* Return value */ + size_t tries, max_tries; /* The # of read attempts to try */ + size_t fixed_tries; /* The # of read attempts to try */ + uint32_t computed_chksum; /* Computed checksum */ + uint32_t stored_chksum; /* Checksum read from file */ + H5F_super_t *ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT @@ -175,40 +179,85 @@ H5F_sblock_load(H5F_t *f, hid_t dxpl_id, haddr_t H5_ATTR_UNUSED addr, void *_uda if(NULL == (dxpl = (H5P_genplist_t *)H5I_object(dxpl_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "can't get property list") - /* Read fixed-size portion of the superblock */ - p = sbuf; - H5_CHECK_OVERFLOW(fixed_size, size_t, haddr_t); - if(H5FD_set_eoa(lf, H5FD_MEM_SUPER, (haddr_t)fixed_size) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "set end of space allocation request failed") - if(H5FD_read(lf, dxpl, H5FD_MEM_SUPER, (haddr_t)0, fixed_size, p) < 0) - HGOTO_ERROR(H5E_FILE, H5E_READERROR, NULL, "unable to read superblock") - - /* Skip over signature (already checked when locating the superblock) */ - p += H5F_SIGNATURE_LEN; - - /* Superblock version */ - super_vers = *p++; - if(super_vers > HDF5_SUPERBLOCK_VERSION_LATEST) - HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, NULL, "bad superblock version number") - if(H5P_set(c_plist, H5F_CRT_SUPER_VERS_NAME, &super_vers) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, NULL, "unable to set superblock version") - - /* Record the superblock version */ - sblock->super_vers = super_vers; + /* Get the # of read attempts */ + tries = max_tries = f->read_attempts; + do { + fixed_tries = max_tries; + do { + /* Read fixed-size portion of the superblock */ + p = sbuf; + H5_CHECK_OVERFLOW(fixed_size, size_t, haddr_t); + if(H5FD_set_eoa(lf, H5FD_MEM_SUPER, (haddr_t)fixed_size) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "set end of space allocation request failed") + if(H5FD_read(lf, dxpl, H5FD_MEM_SUPER, (haddr_t)0, fixed_size, p) < 0) + HGOTO_ERROR(H5E_FILE, H5E_READERROR, NULL, "unable to read superblock") + + /* Skip over signature (already checked when locating the superblock) */ + p += H5F_SIGNATURE_LEN; + + /* Superblock version */ + super_vers = *p++; + + /* A valid version # */ + if(super_vers <= HDF5_SUPERBLOCK_VERSION_LATEST) + break; + + } while (--fixed_tries); + + if(fixed_tries == 0) + /* After all tries (for SWMR access) or after 1 try (for non-SWMR) */ + HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "bad superblock version number after all tries") + else if((max_tries - fixed_tries + 1) > 1) + HDfprintf(stderr, "%s: SUCCESS after %u attempts for fixed data\n", FUNC, max_tries - fixed_tries + 1); + + /* Set superblock version in property list */ + if(H5P_set(c_plist, H5F_CRT_SUPER_VERS_NAME, &super_vers) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, NULL, "unable to set superblock version") + + /* Record the superblock version */ + sblock->super_vers = super_vers; + + /* Sanity check */ + HDassert(((size_t)(p - sbuf)) == fixed_size); + + /* Determine the size of the variable-length part of the superblock */ + variable_size = (size_t)H5F_SUPERBLOCK_VARLEN_SIZE(super_vers, f); + HDassert(variable_size > 0); + HDassert(fixed_size + variable_size <= sizeof(sbuf)); + + /* Read in variable-sized portion of superblock */ + if(H5FD_set_eoa(lf, H5FD_MEM_SUPER, (haddr_t)(fixed_size + variable_size)) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "set end of space allocation request failed") + if(H5FD_read(lf, dxpl, H5FD_MEM_SUPER, (haddr_t)fixed_size, variable_size, p) < 0) + HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to read superblock") + + /* No checksum for version 0 & 1 */ + if(super_vers < HDF5_SUPERBLOCK_VERSION_2) + break; + + /* Decode size of file addresses at this point to get the correct H5F_SIZEOF_ADDR(f) for checksum */ + sizeof_addr = *p++; + if(sizeof_addr == 2 || sizeof_addr == 4 || + sizeof_addr == 8 || sizeof_addr == 16 || sizeof_addr == 32) { - /* Sanity check */ - HDassert(((size_t)(p - sbuf)) == fixed_size); + if(H5P_set(c_plist, H5F_CRT_ADDR_BYTE_NUM_NAME, &sizeof_addr) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, NULL, "unable to set byte number in an address") + shared->sizeof_addr = sizeof_addr; /* Keep a local copy also */ + + /* Retrieve stored and computed checksum */ + H5F_get_checksums(sbuf, fixed_size + H5F_SUPERBLOCK_VARLEN_SIZE(super_vers, f), &stored_chksum, &computed_chksum); - /* Determine the size of the variable-length part of the superblock */ - variable_size = (size_t)H5F_SUPERBLOCK_VARLEN_SIZE(super_vers, f); - HDassert(variable_size > 0); - HDassert(fixed_size + variable_size <= sizeof(sbuf)); + /* Verify correct checksum */ + if(stored_chksum == computed_chksum) + break; + } + } while (--tries); - /* Read in variable-sized portion of superblock */ - if(H5FD_set_eoa(lf, H5FD_MEM_SUPER, (haddr_t)(fixed_size + variable_size)) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "set end of space allocation request failed") - if(H5FD_read(lf, dxpl, H5FD_MEM_SUPER, (haddr_t)fixed_size, variable_size, p) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to read superblock") + if(tries == 0) + /* After all tries (for SWMR access) or after 1 try (for non-SWMR) */ + HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "bad checksum or bad byte number in superblock") + else if((max_tries - tries + 1) > 1) + HDfprintf(stderr, "%s: SUCCESS after %u attempts\n", FUNC, max_tries - tries + 1); /* Check for older version of superblock format */ if(super_vers < HDF5_SUPERBLOCK_VERSION_2) { @@ -394,17 +443,8 @@ H5F_sblock_load(H5F_t *f, hid_t dxpl_id, haddr_t H5_ATTR_UNUSED addr, void *_uda } /* end if */ } /* end if */ else { - uint32_t computed_chksum; /* Computed checksum */ - uint32_t read_chksum; /* Checksum read from file */ - /* Size of file addresses */ - sizeof_addr = *p++; - if(sizeof_addr != 2 && sizeof_addr != 4 && - sizeof_addr != 8 && sizeof_addr != 16 && sizeof_addr != 32) - HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, NULL, "bad byte number in an address") - if(H5P_set(c_plist, H5F_CRT_ADDR_BYTE_NUM_NAME, &sizeof_addr) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, NULL, "unable to set byte number in an address") - shared->sizeof_addr = sizeof_addr; /* Keep a local copy also */ + /* Already decode sizeof_addr when validating checksum up there */ /* Size of file sizes */ sizeof_size = *p++; @@ -426,15 +466,12 @@ H5F_sblock_load(H5F_t *f, hid_t dxpl_id, haddr_t H5_ATTR_UNUSED addr, void *_uda H5F_addr_decode(f, (const uint8_t **)&p, &stored_eof/*out*/); H5F_addr_decode(f, (const uint8_t **)&p, &sblock->root_addr/*out*/); - /* Compute checksum for superblock */ - computed_chksum = H5_checksum_metadata(sbuf, (size_t)(p - sbuf), 0); - /* Decode checksum */ - UINT32DECODE(p, read_chksum); + UINT32DECODE(p, stored_chksum); - /* Verify correct checksum */ - if(read_chksum != computed_chksum) - HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "bad checksum on driver information block") + /* Verify correct checksum with checksum computed via H5F_get_checksums() */ + if(stored_chksum != computed_chksum) + HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "bad checksum on superblock") /* * Check if superblock address is different from base address and diff --git a/src/H5HFcache.c b/src/H5HFcache.c index 07e5b36..eb770d9 100644 --- a/src/H5HFcache.c +++ b/src/H5HFcache.c @@ -78,6 +78,10 @@ static herr_t H5HF__dtable_encode(H5F_t *f, uint8_t **pp, const H5HF_dtable_t *dtable); static herr_t H5HF__dtable_decode(H5F_t *f, const uint8_t **pp, H5HF_dtable_t *dtable); +/* Decode minimum header and full header routines */ +static herr_t H5HF_min_header_decode(const uint8_t **pp, H5HF_hdr_t *hdr); +static herr_t H5HF_full_header_decode(H5F_t *f, hid_t dxpl_id, const uint8_t **pp, H5HF_hdr_t *hdr); + /* Metadata cache (H5AC) callbacks */ static H5HF_hdr_t *H5HF_cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *udata); static herr_t H5HF_cache_hdr_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5HF_hdr_t *hdr, unsigned H5_ATTR_UNUSED * flags_ptr); @@ -268,164 +272,248 @@ H5HF__dtable_encode(H5F_t *f, uint8_t **pp, const H5HF_dtable_t *dtable) /*------------------------------------------------------------------------- - * Function: H5HF_cache_hdr_load + * Function: H5HF_min_header_decode * - * Purpose: Loads a fractal heap header from the disk. + * Purpose: Decodes enough info in the header to determine full header size * - * Return: Success: Pointer to a new fractal heap - * Failure: NULL + * Return: Non-negative on success/Negative on failure * - * Programmer: Quincey Koziol - * koziol@ncsa.uiuc.edu - * Feb 24 2006 + * Programmer: Vailin Choi; Sept 2013 * *------------------------------------------------------------------------- */ -static H5HF_hdr_t * -H5HF_cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata) +static herr_t +H5HF_min_header_decode(const uint8_t **pp, H5HF_hdr_t *hdr) { - H5HF_hdr_t *hdr = NULL; /* Fractal heap info */ - H5HF_hdr_cache_ud_t *udata = (H5HF_hdr_cache_ud_t *)_udata; - size_t size; /* Header size */ - H5WB_t *wb = NULL; /* Wrapped buffer for header data */ - uint8_t hdr_buf[H5HF_HDR_BUF_SIZE]; /* Buffer for header */ - uint8_t *buf; /* Pointer to header buffer */ - const uint8_t *p; /* Pointer into raw data buffer */ - uint32_t stored_chksum; /* Stored metadata checksum value */ - uint32_t computed_chksum; /* Computed metadata checksum value */ - uint8_t heap_flags; /* Status flags for heap */ - H5HF_hdr_t *ret_value; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT /* Check arguments */ - HDassert(f); - HDassert(H5F_addr_defined(addr)); - HDassert(udata); - - /* Allocate space for the fractal heap data structure */ - if(NULL == (hdr = H5HF_hdr_alloc(udata->f))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + HDassert(pp && *pp); + HDassert(hdr); - /* Wrap the local buffer for serialized header info */ - if(NULL == (wb = H5WB_wrap(hdr_buf, sizeof(hdr_buf)))) - HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, NULL, "can't wrap buffer") + /* Magic number */ + if(HDmemcmp(*pp, H5HF_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) + HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, FAIL, "wrong fractal heap header signature") + *pp += H5_SIZEOF_MAGIC; - /* Compute the 'base' size of the fractal heap header on disk */ - size = (size_t)H5HF_HEADER_SIZE(hdr); + /* Version */ + if(**pp != H5HF_HDR_VERSION) + HGOTO_ERROR(H5E_HEAP, H5E_VERSION, FAIL, "wrong fractal heap header version") + (*pp)++; - /* Get a pointer to a buffer that's large enough for serialized header */ - if(NULL == (buf = (uint8_t *)H5WB_actual(wb, size))) - HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, NULL, "can't get actual buffer") + /* General heap information */ + UINT16DECODE(*pp, hdr->id_len); /* Heap ID length */ + UINT16DECODE(*pp, hdr->filter_len); /* I/O filters' encoded length */ - /* Read header from disk */ - if(H5F_block_read(f, H5FD_MEM_FHEAP_HDR, addr, size, dxpl_id, buf) < 0) - HGOTO_ERROR(H5E_HEAP, H5E_READERROR, NULL, "can't read fractal heap header") +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5HF_min_header_decode() */ - /* Get temporary pointer to serialized header */ - p = buf; + +/*------------------------------------------------------------------------- + * Function: H5HF_full_header_decode + * + * Purpose: Decodes info for the full header (fixed-len + variable-len) + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Vailin Choi; Sept 2013 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5HF_full_header_decode(H5F_t *f, hid_t dxpl_id, const uint8_t **pp, H5HF_hdr_t *hdr) +{ + uint8_t heap_flags; /* Status flags for heap */ + herr_t ret_value = SUCCEED; /* Return value */ - /* Magic number */ - if(HDmemcmp(p, H5HF_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) - HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, NULL, "wrong fractal heap header signature") - p += H5_SIZEOF_MAGIC; + FUNC_ENTER_NOAPI_NOINIT - /* Version */ - if(*p++ != H5HF_HDR_VERSION) - HGOTO_ERROR(H5E_HEAP, H5E_VERSION, NULL, "wrong fractal heap header version") + /* Check arguments */ + HDassert(pp && *pp); + HDassert(hdr); - /* General heap information */ - UINT16DECODE(p, hdr->id_len); /* Heap ID length */ - UINT16DECODE(p, hdr->filter_len); /* I/O filters' encoded length */ + /* Decode the minimum header info */ + if(H5HF_min_header_decode(pp, hdr) < 0) + HGOTO_ERROR(H5E_HEAP, H5E_CANTDECODE, FAIL, "can't decode minimum header info") /* Heap status flags */ /* (bit 0: "huge" object IDs have wrapped) */ /* (bit 1: checksum direct blocks) */ - heap_flags = *p++; + heap_flags = **pp; + (*pp)++; + hdr->huge_ids_wrapped = heap_flags & H5HF_HDR_FLAGS_HUGE_ID_WRAPPED; hdr->checksum_dblocks = heap_flags & H5HF_HDR_FLAGS_CHECKSUM_DBLOCKS; /* "Huge" object information */ - UINT32DECODE(p, hdr->max_man_size); /* Max. size of "managed" objects */ - H5F_DECODE_LENGTH(udata->f, p, hdr->huge_next_id); /* Next ID to use for "huge" object */ - H5F_addr_decode(udata->f, &p, &hdr->huge_bt2_addr); /* Address of "huge" object tracker B-tree */ + UINT32DECODE(*pp, hdr->max_man_size); /* Max. size of "managed" objects */ + H5F_DECODE_LENGTH(f, *pp, hdr->huge_next_id); /* Next ID to use for "huge" object */ + H5F_addr_decode(f, pp, &hdr->huge_bt2_addr); /* Address of "huge" object tracker B-tree */ /* "Managed" object free space information */ - H5F_DECODE_LENGTH(udata->f, p, hdr->total_man_free); /* Internal free space in managed direct blocks */ - H5F_addr_decode(udata->f, &p, &hdr->fs_addr); /* Address of free section header */ + H5F_DECODE_LENGTH(f, *pp, hdr->total_man_free); /* Internal free space in managed direct blocks */ + H5F_addr_decode(f, pp, &hdr->fs_addr); /* Address of free section header */ /* Heap statistics */ - H5F_DECODE_LENGTH(udata->f, p, hdr->man_size); - H5F_DECODE_LENGTH(udata->f, p, hdr->man_alloc_size); - H5F_DECODE_LENGTH(udata->f, p, hdr->man_iter_off); - H5F_DECODE_LENGTH(udata->f, p, hdr->man_nobjs); - H5F_DECODE_LENGTH(udata->f, p, hdr->huge_size); - H5F_DECODE_LENGTH(udata->f, p, hdr->huge_nobjs); - H5F_DECODE_LENGTH(udata->f, p, hdr->tiny_size); - H5F_DECODE_LENGTH(udata->f, p, hdr->tiny_nobjs); + H5F_DECODE_LENGTH(f, *pp, hdr->man_size); + H5F_DECODE_LENGTH(f, *pp, hdr->man_alloc_size); + H5F_DECODE_LENGTH(f, *pp, hdr->man_iter_off); + H5F_DECODE_LENGTH(f, *pp, hdr->man_nobjs); + H5F_DECODE_LENGTH(f, *pp, hdr->huge_size); + H5F_DECODE_LENGTH(f, *pp, hdr->huge_nobjs); + H5F_DECODE_LENGTH(f, *pp, hdr->tiny_size); + H5F_DECODE_LENGTH(f, *pp, hdr->tiny_nobjs); /* Managed objects' doubling-table info */ - if(H5HF__dtable_decode(hdr->f, &p, &(hdr->man_dtable)) < 0) - HGOTO_ERROR(H5E_HEAP, H5E_CANTENCODE, NULL, "unable to encode managed obj. doubling table info") - - /* Sanity check */ - /* (allow for checksum not decoded yet) */ - HDassert((size_t)(p - (const uint8_t *)buf) == (size - H5HF_SIZEOF_CHKSUM)); + if(H5HF__dtable_decode(f, pp, &(hdr->man_dtable)) < 0) + HGOTO_ERROR(H5E_HEAP, H5E_CANTENCODE, FAIL, "unable to encode managed obj. doubling table info") /* Check for I/O filter information to decode */ if(hdr->filter_len > 0) { - size_t filter_info_off; /* Offset in header of filter information */ - size_t filter_info_size; /* Size of filter information */ H5O_pline_t *pline; /* Pipeline information from the header on disk */ - /* Compute the offset of the filter info in the header */ - filter_info_off = (size_t)(p - (const uint8_t *)buf); - - /* Compute the size of the extra filter information */ - filter_info_size = (size_t)(hdr->sizeof_size /* Size of size for filtered root direct block */ - + (unsigned)4 /* Size of filter mask for filtered root direct block */ - + hdr->filter_len); /* Size of encoded I/O filter info */ - - /* Compute the heap header's size */ - hdr->heap_size = size + filter_info_size; - - /* Re-size current buffer */ - if(NULL == (buf = (uint8_t *)H5WB_actual(wb, hdr->heap_size))) - HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, NULL, "can't get actual buffer") - - /* Read in I/O filter information */ - /* (and the checksum) */ - if(H5F_block_read(f, H5FD_MEM_FHEAP_HDR, (addr + filter_info_off), (filter_info_size + H5HF_SIZEOF_CHKSUM), dxpl_id, (buf + filter_info_off)) < 0) - HGOTO_ERROR(H5E_HEAP, H5E_READERROR, NULL, "can't read fractal heap header's I/O pipeline filter info") - - /* Point at correct offset in header for the filter information */ - p = buf + filter_info_off; - /* Decode the size of a filtered root direct block */ - H5F_DECODE_LENGTH(udata->f, p, hdr->pline_root_direct_size); + H5F_DECODE_LENGTH(f, *pp, hdr->pline_root_direct_size); /* Decode the filter mask for a filtered root direct block */ - UINT32DECODE(p, hdr->pline_root_direct_filter_mask); + UINT32DECODE(*pp, hdr->pline_root_direct_filter_mask); /* Decode I/O filter information */ - if(NULL == (pline = (H5O_pline_t *)H5O_msg_decode(hdr->f, udata->dxpl_id, NULL, H5O_PLINE_ID, p))) - HGOTO_ERROR(H5E_HEAP, H5E_CANTDECODE, NULL, "can't decode I/O pipeline filters") - p += hdr->filter_len; + if(NULL == (pline = (H5O_pline_t *)H5O_msg_decode(f, dxpl_id, NULL, H5O_PLINE_ID, *pp))) + HGOTO_ERROR(H5E_HEAP, H5E_CANTDECODE, FAIL, "can't decode I/O pipeline filters") + *pp += hdr->filter_len; /* Copy the information into the header's I/O pipeline structure */ if(NULL == H5O_msg_copy(H5O_PLINE_ID, pline, &(hdr->pline))) - HGOTO_ERROR(H5E_HEAP, H5E_CANTCOPY, NULL, "can't copy I/O filter pipeline") + HGOTO_ERROR(H5E_HEAP, H5E_CANTCOPY, FAIL, "can't copy I/O filter pipeline") /* Release the space allocated for the I/O pipeline filters */ H5O_msg_free(H5O_PLINE_ID, pline); } /* end if */ - else - /* Set the heap header's size */ - hdr->heap_size = size; - /* Compute checksum on entire header */ - /* (including the filter information, if present) */ - computed_chksum = H5_checksum_metadata(buf, (size_t)(p - (const uint8_t *)buf), 0); +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5HF_full_header_decode() */ + + +/*------------------------------------------------------------------------- + * Function: H5HF_cache_hdr_load + * + * Purpose: Loads a fractal heap header from the disk. + * + * Return: Success: Pointer to a new fractal heap + * Failure: NULL + * + * Programmer: Quincey Koziol + * koziol@ncsa.uiuc.edu + * Feb 24 2006 + * + *------------------------------------------------------------------------- + */ +static H5HF_hdr_t * +H5HF_cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata) +{ + H5HF_hdr_t *hdr = NULL; /* Fractal heap info */ + H5HF_hdr_cache_ud_t *udata = (H5HF_hdr_cache_ud_t *)_udata; + size_t size, new_size; /* Header size */ + H5WB_t *wb = NULL; /* Wrapped buffer for header data */ + uint8_t hdr_buf[H5HF_HDR_BUF_SIZE]; /* Buffer for header */ + uint8_t *buf; /* Pointer to header buffer */ + const uint8_t *p; /* Pointer into raw data buffer */ + uint32_t stored_chksum; /* Stored metadata checksum value */ + uint32_t computed_chksum; /* Computed metadata checksum value */ + size_t tries, max_tries; /* The # of read attempts */ + size_t fixed_tries; + H5HF_hdr_t *ret_value; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT + + /* Check arguments */ + HDassert(f); + HDassert(H5F_addr_defined(addr)); + HDassert(udata); + + /* Allocate space for the fractal heap data structure */ + if(NULL == (hdr = H5HF_hdr_alloc(udata->f))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + + /* Wrap the local buffer for serialized header info */ + if(NULL == (wb = H5WB_wrap(hdr_buf, sizeof(hdr_buf)))) + HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, NULL, "can't wrap buffer") + + /* Compute the minimum size of the fractal heap header to determine filter info */ + size = (size_t)H5HF_MIN_HEADER_SIZE; + + /* Get the # of read attempts */ + tries = max_tries = H5F_GET_READ_ATTEMPTS(f); + do { + /* Get a pointer to a buffer that's large enough for serialized header */ + if(NULL == (buf = (uint8_t *)H5WB_actual(wb, size))) + HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, NULL, "can't get actual buffer") + + fixed_tries = max_tries; + do { + /* Read minimum header from disk */ + if(H5F_block_read(f, H5FD_MEM_FHEAP_HDR, addr, size, dxpl_id, buf) < 0) + HGOTO_ERROR(H5E_HEAP, H5E_READERROR, NULL, "can't read fractal heap header") + + /* Get temporary pointer to serialized header */ + p = buf; + + /* Decode minimum header info */ + if(H5HF_min_header_decode(&p, hdr) >= 0) + break; + } while (--fixed_tries); + + if(fixed_tries == 0) + /* After all tries (for SWMR access) or after 1 try (for non-SWMR) */ + HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "bad minimum header info in fractal heap header after all tries") + else if((max_tries - fixed_tries + 1) > 1) + HDfprintf(stderr, "%s: SUCCESS after %u attempts for minimum header in fractal heap\n", FUNC, max_tries - fixed_tries + 1); + + /* Full header size */ + new_size = (size_t)H5HF_HEADER_SIZE(hdr); + + /* Check for I/O filter information to decode */ + if(hdr->filter_len > 0) + /* Compute the heap header's size: fixed-len header size + variable-len I/O filter information */ + hdr->heap_size = new_size + + (size_t)(hdr->sizeof_size /* Size of size for filtered root direct block */ + + (unsigned)4 /* Size of filter mask for filtered root direct block */ + + hdr->filter_len); /* Size of encoded I/O filter info */ + else + /* Set the heap header's size: fixed-len header size */ + hdr->heap_size = new_size; + + /* Re-size current buffer */ + if(NULL == (buf = (uint8_t *)H5WB_actual(wb, hdr->heap_size))) + HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, NULL, "can't get actual buffer") + + /* Read the whole header with possibly filter info */ + if(H5F_block_read(f, H5FD_MEM_FHEAP_HDR, addr, hdr->heap_size, dxpl_id, buf) < 0) + HGOTO_ERROR(H5E_HEAP, H5E_READERROR, NULL, "can't read fractal heap header's I/O pipeline filter info") + + /* Retrieve stored and computed checksums */ + H5F_get_checksums(buf, hdr->heap_size, &stored_chksum, &computed_chksum); + + /* Verify checksum */ + if(stored_chksum == computed_chksum) + break; + } while (--tries); + + if(tries == 0) + HGOTO_ERROR(H5E_HEAP, H5E_BADVALUE, NULL, "incorrect metadata checksum after all tries (%u) for fractal heap header", max_tries) + else if((max_tries - tries + 1) > 1) + HDfprintf(stderr, "%s: SUCCESS after %u attempts\n", FUNC, max_tries - tries + 1); + + p = buf; + + /* Decode full header info */ + if(H5HF_full_header_decode(hdr->f, udata->dxpl_id, &p, hdr) < 0) + HGOTO_ERROR(H5E_HEAP, H5E_CANTENCODE, NULL, "unable to decode full header info") /* Metadata checksum */ UINT32DECODE(p, stored_chksum); @@ -433,7 +521,7 @@ H5HF_cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata) /* Sanity check */ HDassert((size_t)(p - (const uint8_t *)buf) == hdr->heap_size); - /* Verify checksum */ + /* Verify checksum with checksum computed via H5F_get_checksums() */ if(stored_chksum != computed_chksum) HGOTO_ERROR(H5E_HEAP, H5E_BADVALUE, NULL, "incorrect metadata checksum for fractal heap header") @@ -802,9 +890,9 @@ H5HF_cache_iblock_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata) if(NULL == (buf = (uint8_t *)H5WB_actual(wb, iblock->size))) HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, NULL, "can't get actual buffer") - /* Read indirect block from disk */ - if(H5F_block_read(f, H5FD_MEM_FHEAP_IBLOCK, addr, iblock->size, dxpl_id, buf) < 0) - HGOTO_ERROR(H5E_HEAP, H5E_READERROR, NULL, "can't read fractal heap indirect block") + /* Read and validate indirect block from disk */ + if(H5F_read_check_metadata(f, H5FD_MEM_FHEAP_IBLOCK, addr, iblock->size, iblock->size, dxpl_id, buf, &computed_chksum) < 0) + HGOTO_ERROR(H5E_BTREE, H5E_BADVALUE, NULL, "incorrect metadata checksum for fractal heap indirect block") /* Get temporary pointer to serialized indirect block */ p = buf; @@ -900,9 +988,6 @@ H5HF_cache_iblock_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata) /* Sanity check */ HDassert(iblock->nchildren); /* indirect blocks w/no children should have been deleted */ - /* Compute checksum on indirect block */ - computed_chksum = H5_checksum_metadata(buf, (size_t)(p - (const uint8_t *)buf), 0); - /* Metadata checksum */ UINT32DECODE(p, stored_chksum); @@ -1403,7 +1488,13 @@ H5HF_cache_dblock_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata) H5HF_direct_t *dblock = NULL; /* Direct block info */ const uint8_t *p; /* Pointer into raw data buffer */ haddr_t heap_addr; /* Address of heap header in the file */ - H5HF_direct_t *ret_value; /* Return value */ + uint32_t computed_chksum; /* Computed metadata checksum value */ + uint32_t stored_chksum; /* Metadata checksum value */ + size_t tries, max_tries; /* The # of read attempts */ + size_t chk_size; /* The size for validating checksum */ + uint8_t *chk_p; /* Pointer to the area for validating checksum */ + size_t read_size; /* Size of filtered direct block to read */ + H5HF_direct_t *ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT @@ -1440,58 +1531,91 @@ H5HF_cache_dblock_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata) if(NULL == (dblock->blk = H5FL_BLK_MALLOC(direct_block, (size_t)dblock->size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - /* Check for I/O filters on this heap */ + /* Determine read_size for filter buffer */ if(hdr->filter_len > 0) { - H5Z_cb_t filter_cb = {NULL, NULL}; /* Filter callback structure */ - size_t nbytes; /* Number of bytes used in buffer, after applying reverse filters */ - void *read_buf; /* Pointer to buffer to read in */ - size_t read_size; /* Size of filtered direct block to read */ - unsigned filter_mask; /* Excluded filters for direct block */ - - /* Check for root direct block */ - if(par_info->iblock == NULL) { - /* Sanity check */ - HDassert(H5F_addr_eq(hdr->man_dtable.table_addr, addr)); + /* Check for root direct block */ + if(par_info->iblock == NULL) { + /* Sanity check */ + HDassert(H5F_addr_eq(hdr->man_dtable.table_addr, addr)); - /* Set up parameters to read filtered direct block */ - read_size = hdr->pline_root_direct_size; - } /* end if */ - else { - /* Sanity check */ - HDassert(H5F_addr_eq(par_info->iblock->ents[par_info->entry].addr, addr)); + /* Set up parameters to read filtered direct block */ + read_size = hdr->pline_root_direct_size; + } /* end if */ + else { + /* Sanity check */ + HDassert(H5F_addr_eq(par_info->iblock->ents[par_info->entry].addr, addr)); - /* Set up parameters to read filtered direct block */ - read_size = par_info->iblock->filt_ents[par_info->entry].size; - } /* end else */ + /* Set up parameters to read filtered direct block */ + read_size = par_info->iblock->filt_ents[par_info->entry].size; + } /* end else */ + } /* end if */ - /* Allocate buffer to perform I/O filtering on */ - if(NULL == (read_buf = H5MM_malloc(read_size))) - HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, NULL, "memory allocation failed for pipeline buffer") + tries = max_tries = H5F_GET_READ_ATTEMPTS(f); + do { + /* Check for I/O filters on this heap */ + if(hdr->filter_len > 0) { + H5Z_cb_t filter_cb = {NULL, NULL}; /* Filter callback structure */ + size_t nbytes; /* Number of bytes used in buffer, after applying reverse filters */ + void *read_buf; /* Pointer to buffer to read in */ + unsigned filter_mask; /* Excluded filters for direct block */ + + /* Allocate buffer to perform I/O filtering on */ + if(NULL == (read_buf = H5MM_malloc(read_size))) + HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, NULL, "memory allocation failed for pipeline buffer") + + /* Read filtered direct block from disk */ + if(H5F_block_read(f, H5FD_MEM_FHEAP_DBLOCK, addr, read_size, dxpl_id, read_buf) < 0) + HGOTO_ERROR(H5E_HEAP, H5E_READERROR, NULL, "can't read fractal heap direct block") + + /* Push direct block data through I/O filter pipeline */ + nbytes = read_size; + filter_mask = udata->filter_mask; + if(H5Z_pipeline(&(hdr->pline), H5Z_FLAG_REVERSE, &filter_mask, H5Z_ENABLE_EDC, filter_cb, &nbytes, &read_size, &read_buf) < 0) + HGOTO_ERROR(H5E_HEAP, H5E_CANTFILTER, NULL, "output pipeline failed") + + /* Sanity check */ + HDassert(nbytes == dblock->size); + + /* Copy un-filtered data into block's buffer */ + HDmemcpy(dblock->blk, read_buf, dblock->size); + + /* Release the read buffer */ + H5MM_xfree(read_buf); + } /* end if */ + else { + /* Read direct block from disk */ + if(H5F_block_read(f, H5FD_MEM_FHEAP_DBLOCK, addr, dblock->size, dxpl_id, dblock->blk) < 0) + HGOTO_ERROR(H5E_HEAP, H5E_READERROR, NULL, "can't read fractal heap direct block") + } /* end else */ + + /* Get out if data block is not checksummed */ + if(!(hdr->checksum_dblocks)) + break; + + /* Decode checksum on direct block, if requested */ + chk_size = (size_t)(H5HF_MAN_ABS_DIRECT_OVERHEAD(hdr) - H5HF_SIZEOF_CHKSUM); + chk_p = dblock->blk + chk_size; + /* Metadata checksum */ + UINT32DECODE(chk_p, stored_chksum); - /* Read filtered direct block from disk */ - if(H5F_block_read(f, H5FD_MEM_FHEAP_DBLOCK, addr, read_size, dxpl_id, read_buf) < 0) - HGOTO_ERROR(H5E_HEAP, H5E_READERROR, NULL, "can't read fractal heap direct block") + chk_p -= H5HF_SIZEOF_CHKSUM; + /* Reset checksum field, for computing the checksum */ + /* (Casting away const OK - QAK) */ + HDmemset(chk_p, 0, (size_t)H5HF_SIZEOF_CHKSUM); - /* Push direct block data through I/O filter pipeline */ - nbytes = read_size; - filter_mask = udata->filter_mask; - if(H5Z_pipeline(&(hdr->pline), H5Z_FLAG_REVERSE, &filter_mask, H5Z_ENABLE_EDC, filter_cb, &nbytes, &read_size, &read_buf) < 0) - HGOTO_ERROR(H5E_HEAP, H5E_CANTFILTER, NULL, "output pipeline failed") + /* Compute checksum on entire direct block */ + computed_chksum = H5_checksum_metadata(dblock->blk, dblock->size, 0); - /* Sanity check */ - HDassert(nbytes == dblock->size); + /* Verify checksum */ + if(stored_chksum == computed_chksum) + break; - /* Copy un-filtered data into block's buffer */ - HDmemcpy(dblock->blk, read_buf, dblock->size); + } while (--tries); - /* Release the read buffer */ - H5MM_xfree(read_buf); - } /* end if */ - else { - /* Read direct block from disk */ - if(H5F_block_read(f, H5FD_MEM_FHEAP_DBLOCK, addr, dblock->size, dxpl_id, dblock->blk) < 0) - HGOTO_ERROR(H5E_HEAP, H5E_READERROR, NULL, "can't read fractal heap direct block") - } /* end else */ + if(tries == 0) + HGOTO_ERROR(H5E_HEAP, H5E_BADVALUE, NULL, "incorrect metadata checksum after all tries (%u) for fractal heap direct block", max_tries) + else if((max_tries - tries + 1) > 1) + HDfprintf(stderr, "%s: SUCCESS after %u attempts\n", FUNC, max_tries - tries + 1); /* Start decoding direct block */ p = dblock->blk; @@ -1524,24 +1648,8 @@ H5HF_cache_dblock_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata) UINT64DECODE_VAR(p, dblock->block_off, hdr->heap_off_size); /* Decode checksum on direct block, if requested */ - if(hdr->checksum_dblocks) { - uint32_t stored_chksum; /* Metadata checksum value */ - uint32_t computed_chksum; /* Computed metadata checksum value */ - - /* Metadata checksum */ - UINT32DECODE(p, stored_chksum); - - /* Reset checksum field, for computing the checksum */ - /* (Casting away const OK - QAK) */ - HDmemset((uint8_t *)p - H5HF_SIZEOF_CHKSUM, 0, (size_t)H5HF_SIZEOF_CHKSUM); - - /* Compute checksum on entire direct block */ - computed_chksum = H5_checksum_metadata(dblock->blk, dblock->size, 0); - - /* Verify checksum */ - if(stored_chksum != computed_chksum) - HGOTO_ERROR(H5E_HEAP, H5E_BADVALUE, NULL, "incorrect metadata checksum for fractal heap direct block") - } /* end if */ + if(hdr->checksum_dblocks) + p += H5HF_SIZEOF_CHKSUM; /* Sanity check */ HDassert((size_t)(p - dblock->blk) == (size_t)H5HF_MAN_ABS_DIRECT_OVERHEAD(hdr)); diff --git a/src/H5HFpkg.h b/src/H5HFpkg.h index b0eba2f..4863edc 100644 --- a/src/H5HFpkg.h +++ b/src/H5HFpkg.h @@ -105,6 +105,14 @@ + H5HF_DTABLE_INFO_SIZE(h) /* Size of managed obj. doubling-table info */ \ ) +/* Size of minimum header to decode for determining the full header size */ +#define H5HF_MIN_HEADER_SIZE ( \ + H5_SIZEOF_MAGIC + /* Signature */ \ + 1 + /* Version */ \ + 2 + /* Heap ID len */ \ + 2 /* I/O filters' encoded len */ \ + ) + /* Size of overhead for a direct block */ #define H5HF_MAN_ABS_DIRECT_OVERHEAD(h) ( \ /* General metadata fields */ \ diff --git a/src/H5Ocache.c b/src/H5Ocache.c index e010ed9..bc9ca13 100644 --- a/src/H5Ocache.c +++ b/src/H5Ocache.c @@ -317,13 +317,17 @@ H5O_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata) { H5O_t *oh = NULL; /* Object header read in */ H5O_cache_ud_t *udata = (H5O_cache_ud_t *)_udata; /* User data for callback */ + H5WB_t *wb = NULL; /* Wrapped buffer for prefix data */ uint8_t read_buf[H5O_SPEC_READ_SIZE]; /* Buffer for speculative read */ - const uint8_t *p; /* Pointer into buffer to decode */ uint8_t *buf = NULL; /* Buffer to decode */ size_t spec_read_size; /* Size of buffer to speculatively read in */ size_t buf_size; /* Size of prefix+chunk #0 buffer */ haddr_t eoa; /* Relative end of file address */ - H5O_t *ret_value; /* Return value */ + size_t tries, max_tries; /* The # of read attempts */ + size_t fixed_tries; /* The # of read attempts for prefix */ + uint32_t stored_chksum; /* Stored metadata checksum value */ + uint32_t computed_chksum; /* Computed metadata checksum value */ + H5O_t *ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT @@ -341,15 +345,89 @@ H5O_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata) /* Compute the size of the speculative object header buffer */ H5_CHECKED_ASSIGN(spec_read_size, size_t, MIN(eoa - addr, H5O_SPEC_READ_SIZE), hsize_t); - /* Attempt to speculatively read both object header prefix and first chunk */ - if(H5F_block_read(f, H5FD_MEM_OHDR, addr, spec_read_size, dxpl_id, read_buf) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_READERROR, NULL, "unable to read object header") - p = read_buf; - /* Allocate space for the object header data structure */ if(NULL == (oh = H5FL_CALLOC(H5O_t))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + /* Wrap the local buffer for serialized header info */ + if(NULL == (wb = H5WB_wrap(read_buf, sizeof(read_buf)))) + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, "can't wrap buffer") + + /* Get the # of read attempts */ + tries = max_tries = H5F_GET_READ_ATTEMPTS(f); + do { + /* Get a pointer to a buffer that's large enough for serialized header */ + if(NULL == (buf = (uint8_t *)H5WB_actual(wb, spec_read_size))) + HGOTO_ERROR(H5E_OHDR, H5E_NOSPACE, NULL, "can't get actual buffer") + + fixed_tries = max_tries; + do { + /* Attempt to speculatively read both object header prefix and first chunk */ + if(H5F_block_read(f, H5FD_MEM_OHDR, addr, spec_read_size, dxpl_id, read_buf) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_READERROR, NULL, "unable to read object header") + + /* Decode header prefix */ + if(H5O_decode_prefix(f, oh, read_buf, udata) >= 0) + break; + + } while (--fixed_tries); + + if(fixed_tries == 0) + /* After all tries (for SWMR access) or after 1 try (for non-SWMR) */ + HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "bad object header prefix after all tries") + else if((max_tries - fixed_tries + 1) > 1) + HDfprintf(stderr, "%s: SUCCESS after %u attempts for fixed data\n", FUNC, max_tries - fixed_tries + 1); + + /* Compute the size of the buffer used */ + buf_size = oh->chunk0_size + (size_t)H5O_SIZEOF_HDR(oh); + + /* Check if the speculative read was large enough to parse the first chunk */ + if(spec_read_size < buf_size) { + + /* Get a pointer to a buffer that's large enough for serialized header */ + if(NULL == (buf = (uint8_t *)H5WB_actual(wb, buf_size))) + HGOTO_ERROR(H5E_OHDR, H5E_NOSPACE, NULL, "can't get actual buffer") + + /* SWMR access */ + if(H5F_INTENT(f) & H5F_ACC_SWMR_READ || H5F_INTENT(f) & H5F_ACC_SWMR_WRITE) { + /* Read the chunk that is bigger than the speculative read size */ + if(H5F_block_read(f, H5FD_MEM_OHDR, addr, buf_size, dxpl_id, buf) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_READERROR, NULL, "unable to read object header") + /* See if the data read now is the same as what is read initially */ + if(HDmemcmp(buf, read_buf, spec_read_size)) { + HDmemset(oh, 0, sizeof(oh)); + /* Decode the prefix again */ + if(H5O_decode_prefix(f, oh, buf, udata) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, "can't decode object header prefix") + } + } else { + /* Copy existing raw data into new buffer */ + HDmemcpy(buf, read_buf, spec_read_size); + + /* Read rest of the raw data */ + if(H5F_block_read(f, H5FD_MEM_OHDR, (addr + spec_read_size), (buf_size - spec_read_size), dxpl_id, (buf + spec_read_size)) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_READERROR, NULL, "unable to read object header data") + } + } else + buf = read_buf; + + /* There is no checksum for version 1 */ + if(oh->version == H5O_VERSION_1) + break; + + /* For version 2: retrieve the stored checksum and compute the checksum */ + H5F_get_checksums(buf, buf_size, &stored_chksum, &computed_chksum); + + /* Verify checksums */ + if(stored_chksum == computed_chksum) + break; + } while (--tries); + + if(tries == 0) + HGOTO_ERROR(H5E_OHDR, H5E_BADVALUE, NULL, "incorrect metadata checksum for object header chunk after all read tries (%u) for %u bytes", max_tries, buf_size) + else if((max_tries - tries + 1) > 1) + HDfprintf(stderr, "%s: SUCCESS after %u attempts\n", FUNC, max_tries - tries + 1); + /* File-specific, non-stored information */ oh->sizeof_size = H5F_SIZEOF_SIZE(udata->common.f); oh->sizeof_addr = H5F_SIZEOF_ADDR(udata->common.f); @@ -358,48 +436,11 @@ H5O_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata) /* Create object header proxy if doing SWMR writes */ HDassert(!oh->proxy_present); if(H5F_INTENT(f) & H5F_ACC_SWMR_WRITE) { - if(H5O_proxy_create(f, dxpl_id, oh) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTCREATE, NULL, "can't create object header proxy") + if(H5O_proxy_create(f, dxpl_id, oh) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTCREATE, NULL, "can't create object header proxy") } /* end if */ else - oh->proxy_addr = HADDR_UNDEF; - - if(H5O_decode_prefix(f, oh, read_buf, udata) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, "can't decode object header prefix") - - /* Compute the size of the buffer required */ - buf_size = oh->chunk0_size + (size_t)H5O_SIZEOF_HDR(oh); - - /* Check if the speculative read was large enough to parse the first chunk */ - if(spec_read_size < buf_size) { - /* Allocate space for a buffer that's large enough for serialized header */ - if(NULL == (buf = (uint8_t *)H5MM_malloc(buf_size))) - HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "can't get actual buffer") - - /* SWMR access */ - if(H5F_INTENT(f) & (H5F_ACC_SWMR_READ | H5F_ACC_SWMR_WRITE)) { - /* Read the chunk that is bigger than the speculative read size */ - if(H5F_block_read(f, H5FD_MEM_OHDR, addr, buf_size, dxpl_id, buf) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_READERROR, NULL, "unable to read object header") - /* See if the data read now is the same as what is read initially */ - if(HDmemcmp(buf, read_buf, spec_read_size)) { - HDmemset(oh, 0, sizeof(*oh)); - - /* Decode the prefix again */ - if(H5O_decode_prefix(f, oh, buf, udata) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, "can't decode object header prefix") - } /* end if */ - } /* end if */ - else { - /* Copy existing raw data into new buffer */ - HDmemcpy(buf, read_buf, spec_read_size); - - /* Read rest of the raw data */ - if(H5F_block_read(f, H5FD_MEM_OHDR, (addr + spec_read_size), (buf_size - spec_read_size), dxpl_id, (buf + spec_read_size)) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_READERROR, NULL, "unable to read object header data") - } /* end else */ - } else - buf = read_buf; + oh->proxy_addr = HADDR_UNDEF; /* Parse the first chunk */ if(H5O__chunk_deserialize(oh, udata->common.addr, oh->chunk0_size, buf, &(udata->common), &oh->cache_info.is_dirty) < 0) @@ -413,8 +454,8 @@ H5O_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata) done: /* Release resources */ - if(buf && buf != read_buf) - H5MM_free(buf); + if(wb && H5WB_unwrap(wb) < 0) + HDONE_ERROR(H5E_OHDR, H5E_CLOSEERROR, NULL, "can't close wrapped buffer") /* Release the [possibly partially initialized] object header on errors */ if(!ret_value && oh) @@ -777,8 +818,15 @@ H5O_cache_chk_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata) HGOTO_ERROR(H5E_OHDR, H5E_NOSPACE, NULL, "can't get actual buffer") /* Read rest of the raw data */ - if(H5F_block_read(f, H5FD_MEM_OHDR, addr, udata->size, dxpl_id, buf) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_READERROR, NULL, "unable to read object header continuation chunk") + if(udata->oh->version == H5O_VERSION_2 && udata->decoding) { + /* Read and validate object header continuation chunk */ + if(H5F_read_check_metadata(f, H5FD_MEM_OHDR, addr, udata->size, udata->size, dxpl_id, buf, NULL) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_BADVALUE, NULL, "incorrect metadata checksum for object header continuation chunk") + } else { + /* Read the header object continuation chunk */ + if(H5F_block_read(f, H5FD_MEM_OHDR, addr, udata->size, dxpl_id, buf) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_READERROR, NULL, "unable to read object header continuation chunk") + } /* Check if we are still decoding the object header */ /* (as opposed to bringing a piece of it back from the file) */ diff --git a/src/H5Pfapl.c b/src/H5Pfapl.c index 6b3d4ac..52aff26 100644 --- a/src/H5Pfapl.c +++ b/src/H5Pfapl.c @@ -170,6 +170,11 @@ #define H5F_ACS_CORE_WRITE_TRACKING_PAGE_SIZE_DEF 524288 #define H5F_ACS_CORE_WRITE_TRACKING_PAGE_SIZE_ENC H5P__encode_size_t #define H5F_ACS_CORE_WRITE_TRACKING_PAGE_SIZE_DEC H5P__decode_size_t +/* Definition for # of read attempts */ +#define H5F_ACS_READ_ATTEMPTS_SIZE sizeof(unsigned) +#define H5F_ACS_READ_ATTEMPTS_DEF 0 +#define H5F_ACS_READ_ATTEMPTS_ENC H5P__encode_unsigned +#define H5F_ACS_READ_ATTEMPTS_DEC H5P__decode_unsigned /******************/ /* Local Typedefs */ @@ -261,6 +266,7 @@ static const unsigned H5F_def_efc_size_g = H5F_ACS_EFC_SIZE_DEF; static const H5FD_file_image_info_t H5F_def_file_image_info_g = H5F_ACS_FILE_IMAGE_INFO_DEF; /* Default file image info and callbacks */ static const hbool_t H5F_def_core_write_tracking_flag_g = H5F_ACS_CORE_WRITE_TRACKING_FLAG_DEF; /* Default setting for core VFD write tracking */ static const size_t H5F_def_core_write_tracking_page_size_g = H5F_ACS_CORE_WRITE_TRACKING_PAGE_SIZE_DEF; /* Default core VFD write tracking page size */ +static const unsigned H5F_def_read_attempts_g = H5F_ACS_READ_ATTEMPTS_DEF; /* Default setting for the # of read attempts */ /*------------------------------------------------------------------------- @@ -422,6 +428,11 @@ H5P_facc_reg_prop(H5P_genclass_t *pclass) NULL, NULL, NULL, NULL) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") + /* Register the # of read attempts */ + if(H5P_register_real(pclass, H5F_ACS_READ_ATTEMPTS_NAME, H5F_ACS_READ_ATTEMPTS_SIZE, &H5F_def_read_attempts_g, + NULL, NULL, NULL, H5F_ACS_READ_ATTEMPTS_ENC, H5F_ACS_READ_ATTEMPTS_DEC, + NULL, NULL, NULL, NULL) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5P_facc_reg_prop() */ @@ -3083,3 +3094,82 @@ done: FUNC_LEAVE_API(ret_value) } + +/*------------------------------------------------------------------------- + * Function: H5Pset_read_attempts + * + * Purpose: Sets the # of read attempts in the file access property list + * when reading metadata with checksum. + * The # of read attempts set via this routine will apply only + * when opening file with SWMR access. When opening file with + * non-SWMR access, the # of read attempts will always be 1. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Vailin Choi; Sept 2013 + * + *------------------------------------------------------------------------- + */ +herr_t +H5Pset_read_attempts(hid_t plist_id, unsigned attempts) +{ + H5P_genplist_t *plist; /* Property list pointer */ + herr_t ret_value = SUCCEED; /* return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE2("e", "iIu", plist_id, attempts); + + /* Cannot set the # of attempts to 0 */ + if(attempts <= 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "number of attempts must be greater than 0"); + + /* Get the plist structure */ + if(NULL == (plist = H5P_object_verify(plist_id, H5P_FILE_ACCESS))) + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") + + /* Set values */ + if(H5P_set(plist, H5F_ACS_READ_ATTEMPTS_NAME, &attempts) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set # of read attempts") + +done: + FUNC_LEAVE_API(ret_value) +} /* H5Pset_read_attempts() */ + + +/*------------------------------------------------------------------------- + * Function: H5Pget_read_attempts + * + * Purpose: Returns the # of read attempts set in the file access property list. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Vailin Choi; Sept 2013 + * + *------------------------------------------------------------------------- + */ +herr_t +H5Pget_read_attempts(hid_t plist_id, unsigned *attempts/*out*/) +{ + H5P_genplist_t *plist; /* Property list pointer */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE2("e", "ix", plist_id, attempts); + + /* Get the plist structure */ + if(NULL == (plist = H5P_object_verify(plist_id, H5P_FILE_ACCESS))) + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") + + /* Get values */ + if(attempts) { + /* Get the # of read attempts set */ + if(H5P_get(plist, H5F_ACS_READ_ATTEMPTS_NAME, attempts) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get alignment") + /* If not set, return the default value */ + if(*attempts == H5F_ACS_READ_ATTEMPTS_DEF) /* 0 */ + *attempts = H5F_READ_ATTEMPTS; + } + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Pget_read_attempts() */ diff --git a/src/H5Ppublic.h b/src/H5Ppublic.h index 32dd0be..25df20a 100644 --- a/src/H5Ppublic.h +++ b/src/H5Ppublic.h @@ -345,6 +345,8 @@ H5_DLL herr_t H5Pset_file_image_callbacks(hid_t fapl_id, H5FD_file_image_callbacks_t *callbacks_ptr); H5_DLL herr_t H5Pget_file_image_callbacks(hid_t fapl_id, H5FD_file_image_callbacks_t *callbacks_ptr); +H5_DLL herr_t H5Pset_read_attempts(hid_t plist_id, unsigned attempts); +H5_DLL herr_t H5Pget_read_attempts(hid_t plist_id, unsigned *attempts/*out*/); H5_DLL herr_t H5Pset_core_write_tracking(hid_t fapl_id, hbool_t is_enabled, size_t page_size); H5_DLL herr_t H5Pget_core_write_tracking(hid_t fapl_id, hbool_t *is_enabled, size_t *page_size); diff --git a/src/H5SMcache.c b/src/H5SMcache.c index eaeb889..23a003a 100644 --- a/src/H5SMcache.c +++ b/src/H5SMcache.c @@ -170,9 +170,9 @@ H5SM_table_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void H5_ATTR_UNUSED *udat if(NULL == (buf = (uint8_t *)H5WB_actual(wb, table->table_size))) HGOTO_ERROR(H5E_SOHM, H5E_NOSPACE, NULL, "can't get actual buffer") - /* Read header from disk */ - if(H5F_block_read(f, H5FD_MEM_SOHM_TABLE, addr, table->table_size, dxpl_id, buf) < 0) - HGOTO_ERROR(H5E_SOHM, H5E_READERROR, NULL, "can't read SOHM table") + /* Read and validate shared message table from disk */ + if(H5F_read_check_metadata(f, H5FD_MEM_SOHM_TABLE, addr, table->table_size, table->table_size, dxpl_id, buf, &computed_chksum) < 0) + HGOTO_ERROR(H5E_SOHM, H5E_BADVALUE, NULL, "incorrect metadata checksum for shared message table") /* Get temporary pointer to serialized table */ p = buf; @@ -226,10 +226,7 @@ H5SM_table_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void H5_ATTR_UNUSED *udat /* Sanity check */ HDassert((size_t)(p - (const uint8_t *)buf) == table->table_size); - /* Compute checksum on entire header */ - computed_chksum = H5_checksum_metadata(buf, (table->table_size - H5SM_SIZEOF_CHECKSUM), 0); - - /* Verify checksum */ + /* Verify checksum with checksum computed via H5F_read_check_metadata() */ if(stored_chksum != computed_chksum) HGOTO_ERROR(H5E_SOHM, H5E_BADVALUE, NULL, "incorrect metadata checksum for shared message table") @@ -478,6 +475,7 @@ H5SM_list_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata) uint32_t stored_chksum; /* Stored metadata checksum value */ uint32_t computed_chksum; /* Computed metadata checksum value */ size_t u; /* Counter variable for messages in list */ + uint32_t chk_size; /* Exact size with checksum at the end */ H5SM_list_t *ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT @@ -503,9 +501,13 @@ H5SM_list_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata) if(NULL == (buf = (uint8_t *)H5WB_actual(wb, udata->header->list_size))) HGOTO_ERROR(H5E_SOHM, H5E_NOSPACE, NULL, "can't get actual buffer") - /* Read list from disk */ - if(H5F_block_read(f, H5FD_MEM_SOHM_INDEX, addr, udata->header->list_size, dxpl_id, buf) < 0) - HGOTO_ERROR(H5E_SOHM, H5E_READERROR, NULL, "can't read SOHM list") + /* Exact size with checksum at the end */ + chk_size = H5SM_LIST_SIZE(udata->f, udata->header->num_messages); + + /* Read and validate shared message list from disk */ + if(H5F_read_check_metadata(f, H5FD_MEM_SOHM_INDEX, addr, udata->header->list_size, chk_size, dxpl_id, buf, &computed_chksum) < 0) + HGOTO_ERROR(H5E_SOHM, H5E_BADVALUE, NULL, "incorrect metadata checksum for shared message list") + /* Get temporary pointer to serialized list index */ p = buf; @@ -529,10 +531,7 @@ H5SM_list_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata) /* Sanity check */ HDassert((size_t)(p - buf) <= udata->header->list_size); - /* Compute checksum on entire header */ - computed_chksum = H5_checksum_metadata(buf, ((size_t)(p - buf) - H5SM_SIZEOF_CHECKSUM), 0); - - /* Verify checksum */ + /* Verify checksum with checksum computed via H5F_read_check_metadata() */ if(stored_chksum != computed_chksum) HGOTO_ERROR(H5E_SOHM, H5E_BADVALUE, NULL, "incorrect metadata checksum for shared message list") diff --git a/test/swmr_generator.c b/test/swmr_generator.c index f556c3d..6946184 100644 --- a/test/swmr_generator.c +++ b/test/swmr_generator.c @@ -335,6 +335,7 @@ int main(int argc, const char *argv[]) gettimeofday(&t, NULL); random_seed = (unsigned)((t.tv_sec * 1000) + t.tv_usec); } /* end if */ + /* random_seed = 125092666; */ srandom(random_seed); /* ALWAYS emit the random seed for possible debugging */ fprintf(stderr, "Using generator random seed (used in sparse test only): %u\n", random_seed); diff --git a/test/testfiles/plist_files/fapl_be b/test/testfiles/plist_files/fapl_be Binary files differindex 0b050d0..509a553 100644 --- a/test/testfiles/plist_files/fapl_be +++ b/test/testfiles/plist_files/fapl_be diff --git a/test/testfiles/plist_files/fapl_le b/test/testfiles/plist_files/fapl_le Binary files differindex 0b050d0..509a553 100644 --- a/test/testfiles/plist_files/fapl_le +++ b/test/testfiles/plist_files/fapl_le diff --git a/test/testfiles/plist_files/lapl_be b/test/testfiles/plist_files/lapl_be Binary files differindex e58bfb4..93da413 100644 --- a/test/testfiles/plist_files/lapl_be +++ b/test/testfiles/plist_files/lapl_be diff --git a/test/testfiles/plist_files/lapl_le b/test/testfiles/plist_files/lapl_le Binary files differindex e58bfb4..93da413 100644 --- a/test/testfiles/plist_files/lapl_le +++ b/test/testfiles/plist_files/lapl_le diff --git a/test/tfile.c b/test/tfile.c index 4de8935..e718473 100644 --- a/test/tfile.c +++ b/test/tfile.c @@ -3709,6 +3709,571 @@ test_swmr_read(void) /**************************************************************** ** +** test_read_attempts(): +** This test checks whether the public routines H5Pset_read_attempts() +** and H5Pget_read_attempts() work properly. +** +*****************************************************************/ +static void +test_read_attempts(void) +{ + hid_t fapl; /* File access property list */ + hid_t file_fapl; /* The file's access property list */ + hid_t fid, fid1, fid2, fid3; /* File IDs */ + unsigned attempts; /* The # of read attempts */ + herr_t ret; /* Generic return value */ + + /* Output message about test being performed */ + MESSAGE(5, ("Testing H5Fget/set_read_attempts()\n")); + + /* + * Set A: + * Tests on verifying the # of read attempts when: + * --setting/getting read attemps from a copy of the + * file access property list. + */ + /* Create a copy of file access property list */ + fapl = H5Pcreate(H5P_FILE_ACCESS); + CHECK(fapl, FAIL, "H5Pcreate"); + + /* Get # of read attempts -- should be the default: 1 */ + ret = H5Pget_read_attempts(fapl, &attempts); + CHECK(ret, FAIL, "H5Pget_read_attempts"); + VERIFY(attempts, 1, "H5Pget_read_attempts"); + + /* Set the # of read attempts to 0--should fail */ + ret = H5Pset_read_attempts(fapl, 0); + VERIFY(ret, FAIL, "H5Pset_read_attempts"); + + /* Set the # of read attempts to a # > 0--should succeed */ + ret = H5Pset_read_attempts(fapl, 9); + VERIFY(ret, 0, "H5Pset_read_attempts"); + + /* Retrieve the # of read attempts -- should succeed and equal to 9 */ + ret = H5Pget_read_attempts(fapl, &attempts); + CHECK(ret, FAIL, "H5Pget_read_attempts"); + VERIFY(attempts, 9, "H5Pget_read_attempts"); + + /* Set the # of read attempts to the non-SWMR access default: H5F_READ_ATTEMPTS --should succeed */ + ret = H5Pset_read_attempts(fapl, H5F_READ_ATTEMPTS); + CHECK(ret, FAIL, "H5Pget_read_attempts"); + + /* Retrieve the # of read attempts -- should succeed and equal to H5F_READ_ATTEMPTS */ + ret = H5Pget_read_attempts(fapl, &attempts); + CHECK(ret, FAIL, "H5Pget_read_attempts"); + VERIFY(attempts, H5F_READ_ATTEMPTS, "H5Pget_read_attempts"); + + /* Set the # of read attempts to the SWMR access default: H5F_SWMR_READ_ATEMPTS --should succeed */ + ret = H5Pset_read_attempts(fapl, H5F_SWMR_READ_ATTEMPTS); + VERIFY(ret, 0, "H5Pset_read_attempts"); + + /* Retrieve the # of read attempts -- should succeed and equal to H5F_SWMR_READ_ATTEMPTS */ + ret = H5Pget_read_attempts(fapl, &attempts); + CHECK(ret, FAIL, "H5Pget_read_attempts"); + VERIFY(attempts, H5F_SWMR_READ_ATTEMPTS, "H5Pget_read_attempts"); + + ret = H5Pclose(fapl); + CHECK(ret, FAIL, "H5Pclose"); + + /* + * Set B: + * Tests on verifying read attempts when: + * --create a file with non-SWMR access + * --opening files with SWMR access + * --using default or non-default file access property list + */ + /* Test 1 */ + /* Create a file with non-SWMR access and default fapl */ + fid = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + CHECK(fid, FAIL, "H5Fcreate"); + + /* Get file's fapl */ + file_fapl = H5Fget_access_plist(fid); + CHECK(file_fapl, FAIL, "H5Fget_access_plist"); + + /* Retrieve the # of read attempts from file's fapl -- should be H5F_READ_ATTEMPTS */ + ret = H5Pget_read_attempts(file_fapl, &attempts); + CHECK(ret, FAIL, "H5Pget_read_attempts"); + VERIFY(attempts, H5F_READ_ATTEMPTS, "H5Pget_read_attempts"); + + /* Close the file */ + ret=H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); + + /* Close file's fapl */ + ret = H5Pclose(file_fapl); + CHECK(ret, FAIL, "H5Pclose"); + + /* Test 2 */ + /* Open the file with SWMR access and default fapl */ + fid = H5Fopen(FILE1, (H5F_ACC_RDONLY | H5F_ACC_SWMR_READ), H5P_DEFAULT); + CHECK(fid, FAIL, "H5Fopen"); + + /* Get file's fapl */ + file_fapl = H5Fget_access_plist(fid); + CHECK(file_fapl, FAIL, "H5Fget_access_plist"); + + /* Retrieve the # of read attempts from file's fapl -- should be H5F_SWMR_READ_ATTEMPTS */ + ret = H5Pget_read_attempts(file_fapl, &attempts); + CHECK(ret, FAIL, "H5Pget_read_attempts"); + VERIFY(attempts, H5F_SWMR_READ_ATTEMPTS, "H5Fget_read_attempts"); + + /* Close the file */ + ret=H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); + + /* Close file's fapl */ + ret = H5Pclose(file_fapl); + CHECK(ret, FAIL, "H5Pclose"); + + /* Test 3 */ + /* Create a copy of file access property list */ + fapl = H5Pcreate(H5P_FILE_ACCESS); + CHECK(fapl, FAIL, "H5Pcreate"); + + /* Set the # of read attempts */ + ret = H5Pset_read_attempts(fapl, 9); + CHECK(ret, FAIL, "H5Pset_read_attempts"); + + /* Open the file with SWMR access and fapl (non-default & set to 9) */ + fid = H5Fopen(FILE1, (H5F_ACC_RDONLY | H5F_ACC_SWMR_READ), fapl); + CHECK(fid, FAIL, "H5Fopen"); + + /* Get file's fapl */ + file_fapl = H5Fget_access_plist(fid); + CHECK(file_fapl, FAIL, "H5Fget_access_plist"); + + /* Retrieve the # of read attempts from file's fapl -- should be 9 */ + ret = H5Pget_read_attempts(file_fapl, &attempts); + CHECK(ret, FAIL, "H5Pget_read_attempts"); + VERIFY(attempts, 9, "H5Pget_read_attempts"); + + /* Close the file */ + ret=H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); + + /* Close file's fapl */ + ret = H5Pclose(file_fapl); + CHECK(ret, FAIL, "H5Pclose"); + + /* Test 4 */ + /* Create a copy of file access property list */ + fapl = H5Pcreate(H5P_FILE_ACCESS); + CHECK(fapl, FAIL, "H5Pcreate"); + + /* Set the # of read attempts */ + ret = H5Pset_read_attempts(fapl, 1); + CHECK(ret, FAIL, "H5Pset_read_attempts"); + + /* Open the file with SWMR access and fapl (non-default & set to 1) */ + fid = H5Fopen(FILE1, (H5F_ACC_RDONLY | H5F_ACC_SWMR_READ), fapl); + CHECK(fid, FAIL, "H5Fopen"); + + /* Get file's fapl */ + file_fapl = H5Fget_access_plist(fid); + CHECK(file_fapl, FAIL, "H5Fget_access_plist"); + + /* Retrieve the # of read attempts from file fapl -- should succeed and equal to 1 */ + ret = H5Pget_read_attempts(file_fapl, &attempts); + CHECK(ret, FAIL, "H5Pget_read_attempts"); + VERIFY(attempts, 1, "H5Pget_read_attempts"); + + /* Close the file */ + ret=H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); + + /* Close file's fapl */ + ret = H5Pclose(file_fapl); + CHECK(ret, FAIL, "H5Pclose"); + + /* Test 5 */ + /* Create a copy of file access property list */ + fapl = H5Pcreate(H5P_FILE_ACCESS); + CHECK(fapl, FAIL, "H5Pcreate"); + + /* Open the file with SWMR_READ and fapl (non-default but unset) */ + fid = H5Fopen(FILE1, (H5F_ACC_RDONLY | H5F_ACC_SWMR_READ), fapl); + CHECK(fid, FAIL, "H5Fopen"); + + /* Get file's fapl */ + file_fapl = H5Fget_access_plist(fid); + CHECK(file_fapl, FAIL, "H5Fget_access_plist"); + + /* Retrieve the # of read attempts from file's fapl -- should be H5F_SWMR_READ_ATTEMPTS */ + ret = H5Pget_read_attempts(file_fapl, &attempts); + CHECK(ret, FAIL, "H5Pget_read_attempts"); + VERIFY(attempts, H5F_SWMR_READ_ATTEMPTS, "H5Pget_read_attempts"); + + /* Close the file */ + ret=H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); + + /* Close file's fapl */ + ret = H5Pclose(file_fapl); + CHECK(ret, FAIL, "H5Pclose"); + + /* + * Set C: + * Tests on verifying read attempts when: + * --create a file with SWMR access + * --opening files with non-SWMR access + * --using default or non-default file access property list + */ + /* Test 1 */ + /* Create a file with non-SWMR access and default fapl */ + fid = H5Fcreate(FILE1, H5F_ACC_TRUNC|H5F_ACC_SWMR_WRITE, H5P_DEFAULT, H5P_DEFAULT); + CHECK(fid, FAIL, "H5Fcreate"); + + /* Get file's fapl */ + file_fapl = H5Fget_access_plist(fid); + CHECK(file_fapl, FAIL, "H5Fget_access_plist"); + + /* Retrieve the # of read attempts from file's fapl -- should be H5F_SWMR_READ_ATTEMPTS */ + ret = H5Pget_read_attempts(file_fapl, &attempts); + CHECK(ret, FAIL, "H5Pget_read_attempts"); + VERIFY(attempts, H5F_SWMR_READ_ATTEMPTS, "H5Pget_read_attempts"); + + /* Close the file */ + ret=H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); + + /* Close file's fapl */ + ret = H5Pclose(file_fapl); + CHECK(ret, FAIL, "H5Pclose"); + + /* Test 2 */ + /* Open the file with non-SWMR access and default fapl */ + fid = H5Fopen(FILE1, H5F_ACC_RDONLY, H5P_DEFAULT); + CHECK(fid, FAIL, "H5Fopen"); + + /* Get file's fapl */ + file_fapl = H5Fget_access_plist(fid); + CHECK(file_fapl, FAIL, "H5Fget_access_plist"); + + /* Retrieve the # of read attempts from file's fapl -- should be H5F_READ_ATTEMPTS */ + ret = H5Pget_read_attempts(file_fapl, &attempts); + CHECK(ret, FAIL, "H5Pget_read_attempts"); + VERIFY(attempts, H5F_READ_ATTEMPTS, "H5Pget_read_attempts"); + + /* Close the file */ + ret=H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); + + /* Close file's fapl */ + ret = H5Pclose(file_fapl); + CHECK(ret, FAIL, "H5Pclose"); + + /* Test 3 */ + /* Create a copy of file access property list */ + fapl = H5Pcreate(H5P_FILE_ACCESS); + CHECK(fapl, FAIL, "H5Pcreate"); + + /* Set the # of read attempts */ + ret = H5Pset_read_attempts(fapl, 9); + CHECK(ret, FAIL, "H5Pset_read_attempts"); + + /* Open the file with SWMR access and fapl (non-default & set to 9) */ + fid = H5Fopen(FILE1, H5F_ACC_RDONLY, fapl); + CHECK(fid, FAIL, "H5Fopen"); + + /* Get file's fapl */ + file_fapl = H5Fget_access_plist(fid); + CHECK(file_fapl, FAIL, "H5Fget_access_plist"); + + /* Retrieve the # of read attempts from file's fapl -- should be H5F_READ_ATTEMPTS */ + ret = H5Pget_read_attempts(file_fapl, &attempts); + CHECK(ret, FAIL, "H5Pget_read_attempts"); + VERIFY(attempts, H5F_READ_ATTEMPTS, "H5Pget_read_attempts"); + + /* Close the file */ + ret=H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); + + /* Close file's fapl */ + ret = H5Pclose(file_fapl); + CHECK(ret, FAIL, "H5Pclose"); + + /* Test 4 */ + /* Create a copy of file access property list */ + fapl = H5Pcreate(H5P_FILE_ACCESS); + CHECK(fapl, FAIL, "H5Pcreate"); + + /* Set the # of read attempts */ + ret = H5Pset_read_attempts(fapl, 1); + CHECK(ret, FAIL, "H5Pset_read_attempts"); + + /* Open the file with SWMR access and fapl (non-default & set to 1) */ + fid = H5Fopen(FILE1, H5F_ACC_RDONLY, fapl); + CHECK(fid, FAIL, "H5Fopen"); + + /* Get file's fapl */ + file_fapl = H5Fget_access_plist(fid); + CHECK(file_fapl, FAIL, "H5Fget_access_plist"); + + /* Retrieve the # of read attempts from file fapl -- should succeed and equal to 1 */ + ret = H5Pget_read_attempts(file_fapl, &attempts); + CHECK(ret, FAIL, "H5Pget_read_attempts"); + VERIFY(attempts, 1, "H5Fget_read_attempts"); + + /* Close the file */ + ret=H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); + + /* Close file's fapl */ + ret = H5Pclose(file_fapl); + CHECK(ret, FAIL, "H5Pclose"); + + /* Test 5 */ + /* Create a copy of file access property list */ + fapl = H5Pcreate(H5P_FILE_ACCESS); + CHECK(fapl, FAIL, "H5Pcreate"); + + /* Open the file with SWMR_READ and fapl (non-default but unset) */ + fid = H5Fopen(FILE1, H5F_ACC_RDONLY, fapl); + CHECK(fid, FAIL, "H5Fopen"); + + /* Get file's fapl */ + file_fapl = H5Fget_access_plist(fid); + CHECK(file_fapl, FAIL, "H5Pget_access_plist"); + + /* Retrieve the # of read attempts from file's fapl -- should be H5F_READ_ATTEMPTS */ + ret = H5Pget_read_attempts(file_fapl, &attempts); + CHECK(ret, FAIL, "H5Pget_read_attempts"); + VERIFY(attempts, H5F_READ_ATTEMPTS, "H5Fget_read_attempts"); + + /* Close the file */ + ret=H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); + + /* Close file's fapl */ + ret = H5Pclose(file_fapl); + CHECK(ret, FAIL, "H5Pclose"); + + + + + /* Create a copy of file access property list */ + fapl = H5Pcreate(H5P_FILE_ACCESS); + CHECK(fapl, FAIL, "H5Pcreate"); + + /* Set the # of read attempts */ + ret = H5Pset_read_attempts(fapl, 9); + CHECK(ret, FAIL, "H5Pset_read_attempts"); + + /* Create a file */ + fid = H5Fcreate(FILE1, H5F_ACC_TRUNC|H5F_ACC_SWMR_WRITE, H5P_DEFAULT, fapl); + CHECK(fid1, FAIL, "H5Fcreate"); + + /* Close the file */ + ret = H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); + + /* Open file again with SWMR access and default fapl */ + fid = H5Fopen(FILE1, H5F_ACC_RDONLY, H5P_DEFAULT); + CHECK(fid, FAIL, "H5Fopen"); + + /* Get file's fapl */ + file_fapl = H5Fget_access_plist(fid); + CHECK(file_fapl, FAIL, "H5Fget_access_plist"); + + /* Retrieve the # of read attempts from file fapl -- should be H5F_READ_ATTEMPTS */ + ret = H5Pget_read_attempts(file_fapl, &attempts); + CHECK(ret, FAIL, "H5Pget_read_attempts"); + VERIFY(attempts, H5F_READ_ATTEMPTS, "H5Pget_read_attempts"); + + /* Close the file's fapl */ + ret = H5Pclose(file_fapl); + CHECK(ret, FAIL, "H5Pclose"); + + /* Close the file */ + ret = H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); + + /* Open file again with SWMR access and default fapl */ + fid = H5Fopen(FILE1, H5F_ACC_SWMR_READ, H5P_DEFAULT); + CHECK(fid2, FAIL, "H5Fopen"); + + /* Get file's fapl */ + file_fapl = H5Fget_access_plist(fid); + CHECK(file_fapl, FAIL, "H5Fget_access_plist"); + + /* Retrieve the # of read attempts from file fapl -- should be H5F_SWMR_READ_ATTEMPTS */ + ret = H5Pget_read_attempts(file_fapl, &attempts); + CHECK(ret, FAIL, "H5Pget_read_attempts"); + VERIFY(attempts, H5F_SWMR_READ_ATTEMPTS, "H5Pget_read_attempts"); + + /* Close the file's fapl */ + ret = H5Pclose(file_fapl); + CHECK(ret, FAIL, "H5Pclose"); + + /* Close the file */ + ret = H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); + + /* + * Set D: + * Tests on verifying read attempts when: + * --create with non-SWMR access + * --opening files with SWMR access + * --H5reopen the files + */ + + /* Create a file */ + fid = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + CHECK(fid1, FAIL, "H5Fcreate"); + + /* Close the file */ + ret = H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); + + /* Open file again with SWMR access and default fapl */ + fid1 = H5Fopen(FILE1, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, H5P_DEFAULT); + CHECK(fid2, FAIL, "H5Fopen"); + + /* Create a copy of file access property list */ + fapl = H5Pcreate(H5P_FILE_ACCESS); + CHECK(fapl, FAIL, "H5Pcreate"); + + /* Set the # of read attempts */ + ret = H5Pset_read_attempts(fapl, 9); + CHECK(ret, FAIL, "H5Pset_read_attempts"); + + /* Open file again with SWMR access and fapl (non-default & set to 9) */ + fid2 = H5Fopen(FILE1, (H5F_ACC_RDONLY | H5F_ACC_SWMR_READ), fapl); + CHECK(fid3, FAIL, "H5Fopen"); + + /* Re-open fid1 */ + fid = H5Freopen(fid1); + CHECK(fid, FAIL, "H5Freopen"); + + /* Get file's fapl */ + file_fapl = H5Fget_access_plist(fid); + CHECK(file_fapl, FAIL, "H5Fget_access_plist"); + + /* Retrieve the # of read attempts from file fapl -- should be H5F_SWMR_READ_ATTEMPTS */ + ret = H5Pget_read_attempts(file_fapl, &attempts); + CHECK(ret, FAIL, "H5Pget_read_attempts"); + VERIFY(attempts, H5F_SWMR_READ_ATTEMPTS, "H5Fget_read_attempts"); + + /* Close the file's fapl */ + ret = H5Pclose(file_fapl); + CHECK(ret, FAIL, "H5Pclose"); + + /* Close the file */ + ret = H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); + + /* Re-open fid2 */ + fid = H5Freopen(fid2); + CHECK(fid, FAIL, "H5Pclose"); + + /* Get file's fapl */ + file_fapl = H5Fget_access_plist(fid); + CHECK(file_fapl, FAIL, "H5Fget_access_plist"); + + /* Retrieve the # of read attempts from file fapl -- should be 9 */ + ret = H5Pget_read_attempts(file_fapl, &attempts); + CHECK(ret, FAIL, "H5Pget_read_attempts"); + VERIFY(attempts, 9, "H5Pget_read_attempts"); + + /* Close the file's fapl */ + ret = H5Pclose(file_fapl); + CHECK(ret, FAIL, "H5Pclose"); + + /* Close the file */ + ret = H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); + + /* Close all the files */ + ret=H5Fclose(fid1); + CHECK(ret, FAIL, "H5Fclose"); + ret=H5Fclose(fid2); + CHECK(ret, FAIL, "H5Fclose"); + + /* + * Set E: + * Tests on verifying read attempts when: + * --create with SWMR access + * --opening files with non-SWMR access + * --H5reopen the files + */ + + /* Create a file */ + fid = H5Fcreate(FILE1, H5F_ACC_TRUNC|H5F_ACC_SWMR_WRITE, H5P_DEFAULT, H5P_DEFAULT); + CHECK(fid1, FAIL, "H5Fcreate"); + + /* Close the file */ + ret = H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); + + /* Open file again with non-SWMR access and default fapl */ + fid1 = H5Fopen(FILE1, H5F_ACC_RDONLY, H5P_DEFAULT); + CHECK(fid2, FAIL, "H5Fopen"); + + /* Create a copy of file access property list */ + fapl = H5Pcreate(H5P_FILE_ACCESS); + CHECK(fapl, FAIL, "H5Pcreate"); + + /* Set the # of read attempts */ + ret = H5Pset_read_attempts(fapl, 9); + CHECK(ret, FAIL, "H5Pset_read_attempts"); + + /* Open file again with non-SWMR access and fapl (non-default & set to 9) */ + fid2 = H5Fopen(FILE1, H5F_ACC_RDONLY, fapl); + CHECK(fid3, FAIL, "H5Fopen"); + + /* Re-open fid1 */ + fid = H5Freopen(fid1); + CHECK(fid, FAIL, "H5Freopen"); + + /* Get file's fapl */ + file_fapl = H5Fget_access_plist(fid); + CHECK(file_fapl, FAIL, "H5Fget_access_plist"); + /* Retrieve the # of read attempts from file fapl -- should be H5F_READ_ATTEMPTS */ + ret = H5Pget_read_attempts(file_fapl, &attempts); + CHECK(ret, FAIL, "H5Pget_read_attempts"); + VERIFY(attempts, H5F_READ_ATTEMPTS, "H5Fget_read_attempts"); + + /* Close the file's fapl */ + ret = H5Pclose(file_fapl); + CHECK(ret, FAIL, "H5Pclose"); + + /* Close the file */ + ret = H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); + + /* Re-open fid2 */ + fid = H5Freopen(fid2); + CHECK(fid, FAIL, "H5Freopen"); + + /* Get file's fapl */ + file_fapl = H5Fget_access_plist(fid); + CHECK(file_fapl, FAIL, "H5Fget_access_plist"); + + /* Retrieve the # of read attempts from file fapl -- should be H5F_READ_ATTEMPTS */ + ret = H5Pget_read_attempts(file_fapl, &attempts); + CHECK(ret, FAIL, "H5Pget_read_attempts"); + VERIFY(attempts, H5F_READ_ATTEMPTS, "H5Pget_read_attempts"); + + /* Close the file's fapl */ + ret = H5Pclose(file_fapl); + CHECK(ret, FAIL, "H5Pclose"); + + /* Close the file */ + ret = H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); + + /* Close all the files */ + ret=H5Fclose(fid1); + CHECK(ret, FAIL, "H5Fclose"); + ret=H5Fclose(fid2); + CHECK(ret, FAIL, "H5Fclose"); + + +} /* end test_read_attempts() */ + +/**************************************************************** +** ** test_deprec(): ** Test deprecated functionality. ** @@ -3891,6 +4456,7 @@ test_file(void) test_libver_macros2(); /* Test the macros for library version comparison */ test_swmr_write(); /* Tests for SWMR write access flag */ test_swmr_read(); /* Tests for SWMR read access flag */ + test_read_attempts(); /* Tests for public routine H5Fget/set_read_attempts() */ #ifndef H5_NO_DEPRECATED_SYMBOLS test_deprec(); /* Test deprecated routines */ #endif /* H5_NO_DEPRECATED_SYMBOLS */ |