diff options
-rwxr-xr-x | src/H5SM.c | 201 | ||||
-rw-r--r-- | src/H5SMcache.c | 603 | ||||
-rwxr-xr-x | src/H5SMpkg.h | 20 | ||||
-rw-r--r-- | src/H5SMtest.c | 8 |
4 files changed, 397 insertions, 435 deletions
@@ -208,9 +208,8 @@ H5SM_init(H5F_t *f, H5P_genplist_t * fc_plist, const H5O_loc_t *ext_loc, hid_t d table_size = (hsize_t) H5SM_TABLE_SIZE(f) + (hsize_t) (table->num_indexes * H5SM_INDEX_HEADER_SIZE(f)); if(HADDR_UNDEF == (table_addr = H5MF_alloc(f, H5FD_MEM_SOHM_TABLE, dxpl_id, table_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "file allocation failed for SOHM table") - /* Cache the new table */ - if(H5AC_set(f, dxpl_id, H5AC_SOHM_TABLE, table_addr, table, H5AC__NO_FLAGS_SET) < 0) + if(H5AC2_set(f, dxpl_id, H5AC2_SOHM_TABLE, table_addr, (size_t)table_size, table, H5AC2__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_CACHE, H5E_CANTINS, FAIL, "can't add SOHM table to cache") /* Record the address of the master table in the file */ @@ -346,6 +345,7 @@ H5SM_type_shared(H5F_t *f, unsigned type_id, hid_t dxpl_id) unsigned type_flag; /* Flag corresponding to message type */ size_t u; /* Local index variable */ htri_t ret_value = FALSE; /* Return value */ + hsize_t table_size; /* Size of SOHM master table in file */ FUNC_ENTER_NOAPI_NOINIT(H5SM_type_shared) @@ -353,15 +353,22 @@ H5SM_type_shared(H5F_t *f, unsigned type_id, hid_t dxpl_id) if(H5SM_type_to_flag(type_id, &type_flag) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTGET, FAIL, "can't map message type to flag") + /* Determine size of table in file */ + table_size = (hsize_t) H5SM_TABLE_SIZE(f) + (hsize_t)(f->shared->sohm_nindexes * H5SM_INDEX_HEADER_SIZE(f)); + + /* Look up the master SOHM table */ if(H5F_addr_defined(f->shared->sohm_addr)) { - if(NULL == (table = (H5SM_master_table_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, NULL, NULL, H5AC_READ))) + if(NULL == (table = (H5SM_master_table_t *)H5AC2_protect(f, dxpl_id, H5AC2_SOHM_TABLE, f->shared->sohm_addr, (size_t)table_size, f, H5AC2_READ))) HGOTO_ERROR(H5E_OHDR, H5E_CANTPROTECT, FAIL, "unable to load SOHM master table") + } /* end if */ else /* No shared messages of any type */ HGOTO_DONE(FALSE) + + /* Search the indexes until we find one that matches this flag or we've * searched them all. */ @@ -371,7 +378,7 @@ H5SM_type_shared(H5F_t *f, unsigned type_id, hid_t dxpl_id) done: /* Release the master SOHM table */ - if(table && H5AC_unprotect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, table, H5AC__NO_FLAGS_SET) < 0) + if(table && H5AC2_unprotect(f, dxpl_id, H5AC2_SOHM_TABLE, f->shared->sohm_addr, (size_t)0, table, H5AC2__NO_FLAGS_SET) < 0) HDONE_ERROR(H5E_OHDR, H5E_CANTUNPROTECT, FAIL, "unable to close SOHM master table") FUNC_LEAVE_NOAPI(ret_value) @@ -397,6 +404,7 @@ H5SM_get_fheap_addr(H5F_t *f, hid_t dxpl_id, unsigned type_id, haddr_t *fheap_ad H5SM_master_table_t *table = NULL; /* Shared object master table */ ssize_t index_num; /* Which index */ herr_t ret_value = SUCCEED; /* Return value */ + hsize_t table_size; /* Size of SOHM master table in file */ FUNC_ENTER_NOAPI(H5SM_get_fheap_addr, FAIL) @@ -404,8 +412,11 @@ H5SM_get_fheap_addr(H5F_t *f, hid_t dxpl_id, unsigned type_id, haddr_t *fheap_ad HDassert(f); HDassert(fheap_addr); + /* Determine size of table in file */ + table_size = (hsize_t) H5SM_TABLE_SIZE(f) + (hsize_t)(f->shared->sohm_nindexes * H5SM_INDEX_HEADER_SIZE(f)); + /* Look up the master SOHM table */ - if(NULL == (table = (H5SM_master_table_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, NULL, NULL, H5AC_READ))) + if(NULL == (table = (H5SM_master_table_t *)H5AC2_protect(f, dxpl_id, H5AC2_SOHM_TABLE, f->shared->sohm_addr, (size_t)table_size, f, H5AC2_READ))) HGOTO_ERROR(H5E_CACHE, H5E_CANTPROTECT, FAIL, "unable to load SOHM master table") /* Look up index for message type */ @@ -417,7 +428,7 @@ H5SM_get_fheap_addr(H5F_t *f, hid_t dxpl_id, unsigned type_id, haddr_t *fheap_ad done: /* Release the master SOHM table */ - if(table && H5AC_unprotect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, table, H5AC__NO_FLAGS_SET) < 0) + if(table && H5AC2_unprotect(f, dxpl_id, H5AC2_SOHM_TABLE, f->shared->sohm_addr, (size_t)0, table, H5AC2__NO_FLAGS_SET) < 0) HDONE_ERROR(H5E_CACHE, H5E_CANTUNPROTECT, FAIL, "unable to close SOHM master table") FUNC_LEAVE_NOAPI(ret_value) @@ -538,7 +549,7 @@ H5SM_delete_index(H5F_t *f, H5SM_index_header_t *header, hid_t dxpl_id, hbool_t /* Determine whether index is a list or a B-tree. */ if(header->index_type == H5SM_LIST) { /* Eject entry from cache */ - if(H5AC_expunge_entry(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr) < 0) + if(H5AC2_expunge_entry(f, dxpl_id, H5AC2_SOHM_LIST, header->index_addr) < 0) HGOTO_ERROR(H5E_HEAP, H5E_CANTREMOVE, FAIL, "unable to remove list index from cache") /* Free the file space used */ @@ -626,7 +637,7 @@ H5SM_create_list(H5F_t *f, H5SM_index_header_t *header, hid_t dxpl_id) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "file allocation failed for SOHM list") /* Put the list into the cache */ - if(H5AC_set(f, dxpl_id, H5AC_SOHM_LIST, addr, list, H5AC__NO_FLAGS_SET) < 0) + if(H5AC2_set(f, dxpl_id, H5AC2_SOHM_LIST, addr, (size_t)size, list, H5AC2__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_CACHE, H5E_CANTINS, HADDR_UNDEF, "can't add SOHM list to cache") /* Set return value */ @@ -726,7 +737,7 @@ H5SM_convert_list_to_btree(H5F_t *f, H5SM_index_header_t *header, } /* end for */ /* Unprotect list in cache and release heap */ - if(H5AC_unprotect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, list, H5AC__DELETED_FLAG) < 0) + if(H5AC2_unprotect(f, dxpl_id, H5AC2_SOHM_LIST, header->index_addr, (size_t)0, list, H5AC2__DELETED_FLAG) < 0) HGOTO_ERROR(H5E_CACHE, H5E_CANTUNPROTECT, FAIL, "unable to release SOHM list") *_list = list = NULL; @@ -771,6 +782,7 @@ H5SM_convert_btree_to_list(H5F_t * f, H5SM_index_header_t * header, hid_t dxpl_i H5SM_list_t *list = NULL; haddr_t btree_addr; herr_t ret_value = SUCCEED; + H5SM_list_cache_ud_t cache_udata; /* User-data for metadata cache callback */ FUNC_ENTER_NOAPI_NOINIT(H5SM_convert_btree_to_list) @@ -786,7 +798,11 @@ H5SM_convert_btree_to_list(H5F_t * f, H5SM_index_header_t * header, hid_t dxpl_i if(HADDR_UNDEF == (header->index_addr = H5SM_create_list(f, header, dxpl_id))) HGOTO_ERROR(H5E_SOHM, H5E_CANTINIT, FAIL, "unable to create shared message list") - if(NULL == (list = (H5SM_list_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, NULL, header, H5AC_WRITE))) + /* Set up user data for metadata cache callback */ + cache_udata.f = f; + cache_udata.header = header; + + if(NULL == (list = (H5SM_list_t *)H5AC2_protect(f, dxpl_id, H5AC2_SOHM_LIST, header->index_addr, H5SM_LIST_SIZE(f, header->list_max), &cache_udata, H5AC2_WRITE))) HGOTO_ERROR(H5E_SOHM, H5E_CANTPROTECT, FAIL, "unable to load SOHM list index") /* Delete the B-tree and have messages copy themselves to the @@ -797,7 +813,7 @@ H5SM_convert_btree_to_list(H5F_t * f, H5SM_index_header_t * header, hid_t dxpl_i done: /* Release the SOHM list from the cache */ - if(list && H5AC_unprotect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, list, H5AC__DIRTIED_FLAG) < 0) + if(list && H5AC2_unprotect(f, dxpl_id, H5AC2_SOHM_LIST, header->index_addr, (size_t)0, list, H5AC2__DIRTIED_FLAG) < 0) HDONE_ERROR(H5E_CACHE, H5E_CANTUNPROTECT, FAIL, "unable to unprotect SOHM index") FUNC_LEAVE_NOAPI(ret_value) @@ -875,6 +891,7 @@ H5SM_can_share(H5F_t *f, hid_t dxpl_id, H5SM_master_table_t *table, ssize_t index_num; htri_t tri_ret; htri_t ret_value = TRUE; + hsize_t table_size; /* Size of SOHM master table in file */ FUNC_ENTER_NOAPI(H5SM_can_share, FAIL) @@ -884,12 +901,15 @@ H5SM_can_share(H5F_t *f, hid_t dxpl_id, H5SM_master_table_t *table, if(tri_ret == FALSE) HGOTO_DONE(FALSE) + /* Determine size of table in file */ + table_size = (hsize_t) H5SM_TABLE_SIZE(f) + (hsize_t)(f->shared->sohm_nindexes * H5SM_INDEX_HEADER_SIZE(f)); + /* Look up the master SOHM table */ /* (use incoming master SOHM table if possible) */ if(table) my_table = table; else { - if(NULL == (my_table = (H5SM_master_table_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, NULL, NULL, H5AC_READ))) + if(NULL == (my_table = (H5SM_master_table_t *)H5AC2_protect(f, dxpl_id, H5AC2_SOHM_TABLE, f->shared->sohm_addr, (size_t)table_size, f, H5AC2_READ))) HGOTO_ERROR(H5E_SOHM, H5E_CANTPROTECT, FAIL, "unable to load SOHM master table") } /* end if */ @@ -913,7 +933,7 @@ H5SM_can_share(H5F_t *f, hid_t dxpl_id, H5SM_master_table_t *table, done: /* Release the master SOHM table, if we protected it */ - if(my_table && my_table != table && H5AC_unprotect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, my_table, H5AC__NO_FLAGS_SET) < 0) + if(my_table && my_table != table && H5AC2_unprotect(f, dxpl_id, H5AC2_SOHM_TABLE, f->shared->sohm_addr, (size_t)0, my_table, H5AC2__NO_FLAGS_SET) < 0) HDONE_ERROR(H5E_SOHM, H5E_CANTRELEASE, FAIL, "unable to close SOHM master table") FUNC_LEAVE_NOAPI(ret_value) @@ -979,10 +999,11 @@ H5SM_try_share(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, unsigned type_id, void *mesg, unsigned *mesg_flags) { H5SM_master_table_t *table = NULL; - unsigned cache_flags = H5AC__NO_FLAGS_SET; + unsigned cache_flags = H5AC2__NO_FLAGS_SET; ssize_t index_num; htri_t tri_ret; htri_t ret_value = TRUE; + hsize_t table_size; /* Size of SOHM master table in file */ FUNC_ENTER_NOAPI(H5SM_try_share, FAIL) @@ -994,8 +1015,11 @@ H5SM_try_share(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, unsigned type_id, if(tri_ret == FALSE) HGOTO_DONE(FALSE) + /* Determine size of table in file */ + table_size = (hsize_t) H5SM_TABLE_SIZE(f) + (hsize_t)(f->shared->sohm_nindexes * H5SM_INDEX_HEADER_SIZE(f)); + /* Look up the master SOHM table */ - if(NULL == (table = (H5SM_master_table_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, NULL, NULL, H5AC_WRITE))) + if(NULL == (table = (H5SM_master_table_t *)H5AC2_protect(f, dxpl_id, H5AC2_SOHM_TABLE, f->shared->sohm_addr, (size_t)table_size, f, H5AC2_WRITE))) HGOTO_ERROR(H5E_CACHE, H5E_CANTPROTECT, FAIL, "unable to load SOHM master table") /* "complex" sharing checks */ @@ -1010,7 +1034,7 @@ H5SM_try_share(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, unsigned type_id, if(table->indexes[index_num].index_addr == HADDR_UNDEF) { if(H5SM_create_index(f, &(table->indexes[index_num]), dxpl_id) < 0) HGOTO_ERROR(H5E_SOHM, H5E_CANTINIT, FAIL, "unable to create SOHM index") - cache_flags |= H5AC__DIRTIED_FLAG; + cache_flags |= H5AC2__DIRTIED_FLAG; } /* end if */ /* Write the message as a shared message. This may or may not cause the @@ -1032,7 +1056,7 @@ H5SM_try_share(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, unsigned type_id, done: /* Release the master SOHM table */ - if(table && H5AC_unprotect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, table, cache_flags) < 0) + if(table && H5AC2_unprotect(f, dxpl_id, H5AC2_SOHM_TABLE, f->shared->sohm_addr, (size_t)0, table, cache_flags) < 0) HDONE_ERROR(H5E_CACHE, H5E_CANTRELEASE, FAIL, "unable to close SOHM master table") FUNC_LEAVE_NOAPI(ret_value) @@ -1137,6 +1161,7 @@ H5SM_write_mesg(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, void * encoding_buf = NULL; /* Buffer for encoded message */ size_t empty_pos = UFAIL; /* Empty entry in list */ herr_t ret_value = SUCCEED; + H5SM_list_cache_ud_t cache_udata; /* User-data for metadata cache callback */ FUNC_ENTER_NOAPI_NOINIT(H5SM_write_mesg) @@ -1173,8 +1198,12 @@ H5SM_write_mesg(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, if(header->index_type == H5SM_LIST) { size_t list_pos; /* Position in a list index */ + /* Set up user data for metadata cache callback */ + cache_udata.f = f; + cache_udata.header = header; + /* The index is a list; get it from the cache */ - if(NULL == (list = (H5SM_list_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, NULL, header, H5AC_WRITE))) + if(NULL == (list = (H5SM_list_t *)H5AC2_protect(f, dxpl_id, H5AC2_SOHM_LIST, header->index_addr, H5SM_LIST_SIZE(f, header->list_max), &cache_udata, H5AC2_WRITE))) HGOTO_ERROR(H5E_CACHE, H5E_CANTPROTECT, FAIL, "unable to load SOHM index") /* See if the message is already in the index and get its location. @@ -1303,7 +1332,7 @@ H5SM_write_mesg(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, } /* end else */ ++(header->num_messages); - (*cache_flags_ptr) |= H5AC__DIRTIED_FLAG; + (*cache_flags_ptr) |= H5AC2__DIRTIED_FLAG; } /* end else */ /* Set the file pointer & message type for the shared component */ @@ -1320,7 +1349,7 @@ done: HDONE_ERROR(H5E_HEAP, H5E_CLOSEERROR, FAIL, "can't close fractal heap") /* If we got a list out of the cache, release it (it is always dirty after writing a message) */ - if(list && H5AC_unprotect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, list, H5AC__DIRTIED_FLAG) < 0) + if(list && H5AC2_unprotect(f, dxpl_id, H5AC2_SOHM_LIST, header->index_addr, (size_t)0, list, H5AC2__DIRTIED_FLAG) < 0) HDONE_ERROR(H5E_CACHE, H5E_CANTUNPROTECT, FAIL, "unable to close SOHM index") if(encoding_buf) @@ -1352,12 +1381,13 @@ herr_t H5SM_delete(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, H5O_shared_t *sh_mesg) { H5SM_master_table_t *table = NULL; - unsigned cache_flags = H5AC__NO_FLAGS_SET; + unsigned cache_flags = H5AC2__NO_FLAGS_SET; ssize_t index_num; void *mesg_buf = NULL; void *native_mesg = NULL; unsigned type_id; /* Message type ID to operate on */ herr_t ret_value = SUCCEED; + hsize_t table_size; /* Size of SOHM master table in file */ FUNC_ENTER_NOAPI(H5SM_delete, FAIL) @@ -1368,8 +1398,11 @@ H5SM_delete(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, H5O_shared_t *sh_mesg) /* Get message type */ type_id = sh_mesg->msg_type_id; + /* Determine size of table in file */ + table_size = (hsize_t) H5SM_TABLE_SIZE(f) + (hsize_t)(f->shared->sohm_nindexes * H5SM_INDEX_HEADER_SIZE(f)); + /* Look up the master SOHM table */ - if(NULL == (table = (H5SM_master_table_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, NULL, NULL, H5AC_WRITE))) + if(NULL == (table = (H5SM_master_table_t *)H5AC2_protect(f, dxpl_id, H5AC2_SOHM_TABLE, f->shared->sohm_addr, (size_t)table_size, f, H5AC2_WRITE))) HGOTO_ERROR(H5E_CACHE, H5E_CANTPROTECT, FAIL, "unable to load SOHM master table") /* Find the correct index and try to delete from it */ @@ -1384,7 +1417,7 @@ H5SM_delete(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, H5O_shared_t *sh_mesg) HGOTO_ERROR(H5E_SOHM, H5E_CANTDELETE, FAIL, "unable to delete mesage from SOHM index") /* Release the master SOHM table */ - if(H5AC_unprotect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, table, cache_flags) < 0) + if(H5AC2_unprotect(f, dxpl_id, H5AC2_SOHM_TABLE, f->shared->sohm_addr, (size_t)0, table, cache_flags) < 0) HGOTO_ERROR(H5E_CACHE, H5E_CANTRELEASE, FAIL, "unable to close SOHM master table") table = NULL; @@ -1402,7 +1435,7 @@ H5SM_delete(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, H5O_shared_t *sh_mesg) done: /* Release the master SOHM table (should only happen on error) */ - if(table && H5AC_unprotect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, table, cache_flags) < 0) + if(table && H5AC2_unprotect(f, dxpl_id, H5AC2_SOHM_TABLE, f->shared->sohm_addr, (size_t)0, table, cache_flags) < 0) HDONE_ERROR(H5E_CACHE, H5E_CANTRELEASE, FAIL, "unable to close SOHM master table") /* Release any native message we decoded */ @@ -1583,6 +1616,7 @@ H5SM_delete_from_index(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, void *encoding_buf = NULL; /* The encoded message (out) */ unsigned type_id; /* Message type to operate on */ herr_t ret_value = SUCCEED; + H5SM_list_cache_ud_t cache_udata; /* User-data for metadata cache callback */ FUNC_ENTER_NOAPI_NOINIT(H5SM_delete_from_index) @@ -1631,8 +1665,12 @@ H5SM_delete_from_index(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, if(header->index_type == H5SM_LIST) { size_t list_pos; /* Position of the message in the list */ + /* Set up user data for metadata cache callback */ + cache_udata.f = f; + cache_udata.header = header; + /* If the index is stored as a list, get it from the cache */ - if(NULL == (list = (H5SM_list_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, NULL, header, H5AC_WRITE))) + if(NULL == (list = (H5SM_list_t *)H5AC2_protect(f, dxpl_id, H5AC2_SOHM_LIST, header->index_addr, H5SM_LIST_SIZE(f, header->list_max), &cache_udata, H5AC2_WRITE))) HGOTO_ERROR(H5E_SOHM, H5E_CANTPROTECT, FAIL, "unable to load SOHM index") /* Find the message in the list */ @@ -1667,7 +1705,7 @@ H5SM_delete_from_index(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, /* Updated the index header, so set its dirty flag */ --header->num_messages; - *cache_flags |= H5AC__DIRTIED_FLAG; + *cache_flags |= H5AC2__DIRTIED_FLAG; /* Remove the message from the index */ if(header->index_type == H5SM_LIST) @@ -1690,7 +1728,7 @@ H5SM_delete_from_index(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, if(header->num_messages == 0) { /* Unprotect cache and release heap */ - if(list && H5AC_unprotect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, list, H5AC__DELETED_FLAG) < 0) + if(list && H5AC2_unprotect(f, dxpl_id, H5AC2_SOHM_LIST, header->index_addr, (size_t)0, list, H5AC2__DELETED_FLAG) < 0) HGOTO_ERROR(H5E_CACHE, H5E_CANTUNPROTECT, FAIL, "unable to release SOHM list") list = NULL; @@ -1714,7 +1752,7 @@ H5SM_delete_from_index(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, done: /* Release the SOHM list */ - if(list && H5AC_unprotect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, list, H5AC__DIRTIED_FLAG) < 0) + if(list && H5AC2_unprotect(f, dxpl_id, H5AC2_SOHM_LIST, header->index_addr, (size_t)0, list, H5AC2__DIRTIED_FLAG) < 0) HDONE_ERROR(H5E_CACHE, H5E_CANTUNPROTECT, FAIL, "unable to close SOHM index") /* Release the fractal heap if we opened it */ @@ -1751,6 +1789,7 @@ H5SM_get_info(const H5O_loc_t *ext_loc, H5P_genplist_t *fc_plist, hid_t dxpl_id) H5O_shmesg_table_t sohm_table; /* SOHM message from superblock extension */ H5SM_master_table_t *table = NULL; /* SOHM master table */ herr_t ret_value = SUCCEED; /* Return value */ + hsize_t table_size; /* Size of SOHM master table in file */ FUNC_ENTER_NOAPI(H5SM_get_info, FAIL) @@ -1791,8 +1830,11 @@ H5SM_get_info(const H5O_loc_t *ext_loc, H5P_genplist_t *fc_plist, hid_t dxpl_id) HDassert(H5F_addr_defined(shared->sohm_addr)); HDassert(shared->sohm_nindexes > 0 && shared->sohm_nindexes <= H5O_SHMESG_MAX_NINDEXES); + /* Determine size of table in file */ + table_size = (hsize_t) H5SM_TABLE_SIZE(f) + (hsize_t)(shared->sohm_nindexes * H5SM_INDEX_HEADER_SIZE(f)); + /* Read the rest of the SOHM table information from the cache */ - if(NULL == (table = (H5SM_master_table_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_TABLE, shared->sohm_addr, NULL, NULL, H5AC_READ))) + if(NULL == (table = (H5SM_master_table_t *)H5AC2_protect(f, dxpl_id, H5AC2_SOHM_TABLE, shared->sohm_addr, (size_t)table_size, f, H5AC2_READ))) HGOTO_ERROR(H5E_CACHE, H5E_CANTPROTECT, FAIL, "unable to load SOHM master table") /* Get index conversion limits */ @@ -1831,7 +1873,7 @@ H5SM_get_info(const H5O_loc_t *ext_loc, H5P_genplist_t *fc_plist, hid_t dxpl_id) done: /* Release the master SOHM table if we took it out of the cache */ - if(table && H5AC_unprotect(f, dxpl_id, H5AC_SOHM_TABLE, shared->sohm_addr, table, H5AC__NO_FLAGS_SET) < 0) + if(table && H5AC2_unprotect(f, dxpl_id, H5AC2_SOHM_TABLE, shared->sohm_addr, (size_t)0, table, H5AC2__NO_FLAGS_SET) < 0) HDONE_ERROR(H5E_CACHE, H5E_CANTRELEASE, FAIL, "unable to close SOHM master table") FUNC_LEAVE_NOAPI(ret_value) @@ -2009,6 +2051,8 @@ H5SM_get_refcount(H5F_t *f, hid_t dxpl_id, unsigned type_id, size_t buf_size; /* Size of the encoded message */ void * encoding_buf = NULL; /* Buffer for encoded message */ herr_t ret_value = SUCCEED; /* Return value */ + H5SM_list_cache_ud_t cache_udata; /* User-data for metadata cache callback */ + hsize_t table_size; /* Size of SOHM master table in file */ FUNC_ENTER_NOAPI_NOINIT(H5SM_get_refcount) @@ -2017,8 +2061,11 @@ H5SM_get_refcount(H5F_t *f, hid_t dxpl_id, unsigned type_id, HDassert(sh_mesg); HDassert(ref_count); + /* Determine size of table in file */ + table_size = (hsize_t) H5SM_TABLE_SIZE(f) + (hsize_t)(f->shared->sohm_nindexes * H5SM_INDEX_HEADER_SIZE(f)); + /* Look up the master SOHM table */ - if(NULL == (table = (H5SM_master_table_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, NULL, NULL, H5AC_READ))) + if(NULL == (table = (H5SM_master_table_t *)H5AC2_protect(f, dxpl_id, H5AC2_SOHM_TABLE, f->shared->sohm_addr, (size_t)table_size, f, H5AC2_READ))) HGOTO_ERROR(H5E_CACHE, H5E_CANTPROTECT, FAIL, "unable to load SOHM master table") /* Find the correct index and find the message in it */ @@ -2026,6 +2073,10 @@ H5SM_get_refcount(H5F_t *f, hid_t dxpl_id, unsigned type_id, HGOTO_ERROR(H5E_SOHM, H5E_NOTFOUND, FAIL, "unable to find correct SOHM index") header = &(table->indexes[index_num]); + /* Set up user data for metadata cache callback */ + cache_udata.f = f; + cache_udata.header = header; + /* Open the heap for this message type */ if(NULL == (fheap = H5HF_open(f, dxpl_id, header->heap_addr))) HGOTO_ERROR(H5E_HEAP, H5E_CANTOPENOBJ, FAIL, "unable to open fractal heap") @@ -2052,7 +2103,7 @@ H5SM_get_refcount(H5F_t *f, hid_t dxpl_id, unsigned type_id, size_t list_pos; /* Position of the message in the list */ /* If the index is stored as a list, get it from the cache */ - if(NULL == (list = (H5SM_list_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, NULL, header, H5AC_READ))) + if(NULL == (list = (H5SM_list_t *)H5AC2_protect(f, dxpl_id, H5AC2_SOHM_LIST, header->index_addr, H5SM_LIST_SIZE(f, header->list_max), &cache_udata, H5AC2_READ))) HGOTO_ERROR(H5E_SOHM, H5E_CANTPROTECT, FAIL, "unable to load SOHM index") /* Find the message in the list */ @@ -2077,9 +2128,9 @@ H5SM_get_refcount(H5F_t *f, hid_t dxpl_id, unsigned type_id, done: /* Release resources */ - if(list && H5AC_unprotect(f, dxpl_id, H5AC_SOHM_LIST, header->index_addr, list, H5AC__NO_FLAGS_SET) < 0) + if(list && H5AC2_unprotect(f, dxpl_id, H5AC2_SOHM_LIST, header->index_addr, (size_t)0, list, H5AC2__NO_FLAGS_SET) < 0) HDONE_ERROR(H5E_CACHE, H5E_CANTUNPROTECT, FAIL, "unable to close SOHM index") - if(table && H5AC_unprotect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, table, H5AC__NO_FLAGS_SET) < 0) + if(table && H5AC2_unprotect(f, dxpl_id, H5AC2_SOHM_TABLE, f->shared->sohm_addr, (size_t)0, table, H5AC2__NO_FLAGS_SET) < 0) HDONE_ERROR(H5E_CACHE, H5E_CANTRELEASE, FAIL, "unable to close SOHM master table") if(fheap && H5HF_close(fheap, dxpl_id) < 0) HDONE_ERROR(H5E_HEAP, H5E_CLOSEERROR, FAIL, "can't close fractal heap") @@ -2290,6 +2341,63 @@ done: /*------------------------------------------------------------------------- + * Function: H5SM_table_dest + * + * Purpose: Frees memory used by the SOHM table. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: James Laird + * November 6, 2006 + * + *------------------------------------------------------------------------- + */ +herr_t +H5SM_table_dest(H5SM_master_table_t *table) +{ + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5SM_table_dest) + + /* Sanity check */ + HDassert(table); + HDassert(table->indexes); + + H5FL_ARR_FREE(H5SM_index_header_t, table->indexes); + + H5FL_FREE(H5SM_master_table_t, table); + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5SM_table_dest() */ + + +/*------------------------------------------------------------------------- + * Function: H5SM_list_dest + * + * Purpose: Frees all memory used by the list. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: James Laird + * November 6, 2006 + * + *------------------------------------------------------------------------- + */ +herr_t +H5SM_list_dest(H5SM_list_t *list) +{ + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5SM_list_dest) + + HDassert(list); + HDassert(list->messages); + + H5FL_ARR_FREE(H5SM_sohm_t, list->messages); + + H5FL_FREE(H5SM_list_t, list); + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5SM_list_dest() */ + + +/*------------------------------------------------------------------------- * Function: H5SM_table_debug * * Purpose: Print debugging information for the master table. @@ -2312,6 +2420,7 @@ H5SM_table_debug(H5F_t *f, hid_t dxpl_id, haddr_t table_addr, H5SM_master_table_t *table = NULL; /* SOHM master table */ unsigned x; /* Counter variable */ herr_t ret_value = SUCCEED; /* Return value */ + hsize_t table_size; /* Size of SOHM master table in file */ FUNC_ENTER_NOAPI(H5SM_table_debug, FAIL) @@ -2339,8 +2448,11 @@ H5SM_table_debug(H5F_t *f, hid_t dxpl_id, haddr_t table_addr, if(num_indexes == 0 || num_indexes > H5O_SHMESG_MAX_NINDEXES) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "number of indexes must be between 1 and H5O_SHMESG_MAX_NINDEXES") + /* Determine size of table in file */ + table_size = (hsize_t) H5SM_TABLE_SIZE(f) + (hsize_t) (f->shared->sohm_nindexes * H5SM_INDEX_HEADER_SIZE(f)); + /* Look up the master SOHM table */ - if(NULL == (table = (H5SM_master_table_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_TABLE, table_addr, NULL, NULL, H5AC_READ))) + if(NULL == (table = (H5SM_master_table_t *)H5AC2_protect(f, dxpl_id, H5AC2_SOHM_TABLE, table_addr, (size_t)table_size, f, H5AC2_READ))) HGOTO_ERROR(H5E_CACHE, H5E_CANTPROTECT, FAIL, "unable to load SOHM master table") HDfprintf(stream, "%*sShared Message Master Table...\n", indent, ""); @@ -2368,7 +2480,7 @@ H5SM_table_debug(H5F_t *f, hid_t dxpl_id, haddr_t table_addr, } /* end for */ done: - if(table && H5AC_unprotect(f, dxpl_id, H5AC_SOHM_TABLE, table_addr, table, H5AC__NO_FLAGS_SET) < 0) + if(table && H5AC2_unprotect(f, dxpl_id, H5AC2_SOHM_TABLE, table_addr, (size_t)0, table, H5AC2__NO_FLAGS_SET) < 0) HDONE_ERROR(H5E_CACHE, H5E_CANTRELEASE, FAIL, "unable to close SOHM master table") FUNC_LEAVE_NOAPI(ret_value) @@ -2399,6 +2511,7 @@ H5SM_list_debug(H5F_t *f, hid_t dxpl_id, haddr_t list_addr, H5SM_index_header_t header; /* A "false" header used to read the list */ unsigned x; /* Counter variable */ herr_t ret_value = SUCCEED; /* Return value */ + H5SM_list_cache_ud_t cache_udata; /* User-data for metadata cache callback */ FUNC_ENTER_NOAPI(H5SM_list_debug, FAIL) @@ -2420,8 +2533,12 @@ H5SM_list_debug(H5F_t *f, hid_t dxpl_id, haddr_t list_addr, header.index_type = H5SM_LIST; header.index_addr = list_addr; + /* Set up user data for metadata cache callback */ + cache_udata.f = f; + cache_udata.header = &header; + /* Get the list from the cache */ - if(NULL == (list = (H5SM_list_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_LIST, list_addr, NULL, &header, H5AC_READ))) + if(NULL == (list = (H5SM_list_t *)H5AC2_protect(f, dxpl_id, H5AC2_SOHM_LIST, list_addr, H5SM_LIST_SIZE(f, header.list_max), &cache_udata, H5AC2_READ))) HGOTO_ERROR(H5E_CACHE, H5E_CANTPROTECT, FAIL, "unable to load SOHM index") HDfprintf(stream, "%*sShared Message List Index...\n", indent, ""); @@ -2453,7 +2570,7 @@ H5SM_list_debug(H5F_t *f, hid_t dxpl_id, haddr_t list_addr, } /* end for */ done: - if(list && H5AC_unprotect(f, dxpl_id, H5AC_SOHM_LIST, list_addr, list, H5AC__NO_FLAGS_SET) < 0) + if(list && H5AC2_unprotect(f, dxpl_id, H5AC2_SOHM_LIST, list_addr, (size_t)0, list, H5AC2__NO_FLAGS_SET) < 0) HDONE_ERROR(H5E_CACHE, H5E_CANTUNPROTECT, FAIL, "unable to close SOHM index") FUNC_LEAVE_NOAPI(ret_value) @@ -2483,6 +2600,7 @@ H5SM_ih_size(H5F_t *f, hid_t dxpl_id, H5F_info_t *finfo) H5HF_t *fheap = NULL; /* Fractal heap handle */ unsigned u; /* Local index variable */ herr_t ret_value = SUCCEED; /* Return value */ + hsize_t table_size; /* Size of SOHM master table in file */ FUNC_ENTER_NOAPI(H5SM_ih_size, FAIL) @@ -2491,8 +2609,11 @@ H5SM_ih_size(H5F_t *f, hid_t dxpl_id, H5F_info_t *finfo) HDassert(H5F_addr_defined(f->shared->sohm_addr)); HDassert(finfo); + /* Determine size of table in file */ + table_size = (hsize_t) H5SM_TABLE_SIZE(f) + (hsize_t)(f->shared->sohm_nindexes * H5SM_INDEX_HEADER_SIZE(f)); + /* Look up the master SOHM table */ - if(NULL == (table = (H5SM_master_table_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, NULL, NULL, H5AC_READ))) + if(NULL == (table = (H5SM_master_table_t *)H5AC2_protect(f, dxpl_id, H5AC2_SOHM_TABLE, f->shared->sohm_addr, (size_t)table_size, f, H5AC2_READ))) HGOTO_ERROR(H5E_CACHE, H5E_CANTPROTECT, FAIL, "unable to load SOHM master table") /* Get SOHM header size */ @@ -2531,7 +2652,7 @@ done: /* Release resources */ if(fheap && H5HF_close(fheap, dxpl_id) < 0) HDONE_ERROR(H5E_HEAP, H5E_CLOSEERROR, FAIL, "can't close fractal heap") - if(table && H5AC_unprotect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, table, H5AC__NO_FLAGS_SET) < 0) + if(table && H5AC2_unprotect(f, dxpl_id, H5AC2_SOHM_TABLE, f->shared->sohm_addr, (size_t)0, table, H5AC2__NO_FLAGS_SET) < 0) HDONE_ERROR(H5E_CACHE, H5E_CANTRELEASE, FAIL, "unable to close SOHM master table") FUNC_LEAVE_NOAPI(ret_value) diff --git a/src/H5SMcache.c b/src/H5SMcache.c index 371344a..3e28793 100644 --- a/src/H5SMcache.c +++ b/src/H5SMcache.c @@ -53,38 +53,44 @@ /********************/ /* Metadata cache (H5AC) callbacks */ -static H5SM_master_table_t *H5SM_table_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *udata1, void *table); -static herr_t H5SM_table_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5SM_master_table_t *table); -static herr_t H5SM_table_dest(H5F_t *f, H5SM_master_table_t* table); -static herr_t H5SM_table_clear(H5F_t *f, H5SM_master_table_t *table, hbool_t destroy); -static herr_t H5SM_table_size(const H5F_t *f, const H5SM_master_table_t *table, size_t *size_ptr); -static H5SM_list_t *H5SM_list_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *udata1, void *udata2); -static herr_t H5SM_list_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5SM_list_t *list); -static herr_t H5SM_list_dest(H5F_t *f, H5SM_list_t* list); -static herr_t H5SM_list_clear(H5F_t *f, H5SM_list_t *list, hbool_t destroy); -static herr_t H5SM_list_size(const H5F_t *f, const H5SM_list_t UNUSED *list, size_t *size_ptr); + +static void *H5SM_table_deserialize(haddr_t addr, size_t len, const void *image, const void *udata, hbool_t *dirty); +static herr_t H5SM_table_serialize(const H5F_t * f, haddr_t addr, size_t len, void *image, + void *thing, unsigned *flags, haddr_t *new_addr, + size_t *new_len, void **new_image); +static herr_t H5SM_table_free_icr(haddr_t addr, size_t len, void *thing); + +static void *H5SM_list_deserialize(haddr_t addr, size_t len, const void *image, const void *udata, hbool_t *dirty); +static herr_t H5SM_list_serialize(const H5F_t * f, haddr_t addr, size_t len, void *image, + void *thing, unsigned *flags, haddr_t *new_addr, + size_t *new_len, void **new_image); +static herr_t H5SM_list_free_icr(haddr_t addr, size_t len, void *thing); /*********************/ /* Package Variables */ /*********************/ -/* H5SM inherits cache-like properties from H5AC */ -const H5AC_class_t H5AC_SOHM_TABLE[1] = {{ - H5AC_SOHM_TABLE_ID, - (H5AC_load_func_t)H5SM_table_load, - (H5AC_flush_func_t)H5SM_table_flush, - (H5AC_dest_func_t)H5SM_table_dest, - (H5AC_clear_func_t)H5SM_table_clear, - (H5AC_size_func_t)H5SM_table_size, +/* H5SM inherits cache-like properties from H5AC2 */ +const H5AC2_class_t H5AC2_SOHM_TABLE[1] = {{ + H5AC2_SOHM_TABLE_ID, + "shared object header message", + H5FD_MEM_SOHM_TABLE, + H5SM_table_deserialize, + NULL, + H5SM_table_serialize, + H5SM_table_free_icr, + NULL }}; -const H5AC_class_t H5AC_SOHM_LIST[1] = {{ - H5AC_SOHM_LIST_ID, - (H5AC_load_func_t)H5SM_list_load, - (H5AC_flush_func_t)H5SM_list_flush, - (H5AC_dest_func_t)H5SM_list_dest, - (H5AC_clear_func_t)H5SM_list_clear, - (H5AC_size_func_t)H5SM_list_size, +const H5AC2_class_t H5AC2_SOHM_LIST[1] = {{ + H5AC2_SOHM_LIST_ID, + "shared object header message", + H5FD_MEM_SOHM_INDEX, + H5SM_list_deserialize, + NULL, + H5SM_list_serialize, + H5SM_list_free_icr, + NULL }}; @@ -100,38 +106,42 @@ const H5AC_class_t H5AC_SOHM_LIST[1] = {{ /*------------------------------------------------------------------------- - * Function: H5SM_table_load + * Function: H5SM_table_deserialize * - * Purpose: Loads the master table of Shared Object Header Message - * indexes. + * Purpose: Deserialize the data structure from disk. * - * Return: Non-negative on success/Negative on failure + * Return: Success: SUCCEED + * Failure: FAIL * * Programmer: James Laird * November 6, 2006 * + * Changes: Mike McGreevy + * mcgreevy@hdfgroup.org + * June 26, 2008 + * Converted from H5SM_table_load() + * *------------------------------------------------------------------------- */ -static H5SM_master_table_t * -H5SM_table_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1, void UNUSED *udata2) +static void * +H5SM_table_deserialize(haddr_t UNUSED addr, size_t UNUSED len, + const void *image, const void *_udata, hbool_t UNUSED *dirty) { H5SM_master_table_t *table = NULL; - size_t size; /* Size of SOHM master table on disk */ - H5WB_t *wb = NULL; /* Wrapped buffer for table data */ - uint8_t tbl_buf[H5SM_TBL_BUF_SIZE]; /* Buffer for table */ - uint8_t *buf; /* Reading buffer */ + const H5F_t *f = (const H5F_t *)_udata; /* File pointer */ const uint8_t *p; /* Pointer into input buffer */ uint32_t stored_chksum; /* Stored metadata checksum value */ uint32_t computed_chksum; /* Computed metadata checksum value */ size_t x; /* Counter variable for index headers */ H5SM_master_table_t *ret_value; - FUNC_ENTER_NOAPI_NOINIT(H5SM_table_load) + FUNC_ENTER_NOAPI_NOINIT(H5SM_table_deserialize) /* Verify that we're reading version 0 of the table; this is the only * version defined so far. */ HDassert(f->shared->sohm_vers == HDF5_SHAREDHEADER_VERSION); + HDassert(image); /* Allocate space for the master table in memory */ if(NULL == (table = H5FL_CALLOC(H5SM_master_table_t))) @@ -144,25 +154,8 @@ H5SM_table_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1 HDassert(addr != HADDR_UNDEF); HDassert(table->num_indexes > 0); - /* Wrap the local buffer for serialized table info */ - if(NULL == (wb = H5WB_wrap(tbl_buf, sizeof(tbl_buf)))) - HGOTO_ERROR(H5E_SOHM, H5E_CANTINIT, NULL, "can't wrap buffer") - - /* Compute the size of the SOHM table header on disk. This is the "table" itself - * plus each index within the table - */ - size = H5SM_TABLE_SIZE(f) + (table->num_indexes * H5SM_INDEX_HEADER_SIZE(f)); - - /* Get a pointer to a buffer that's large enough for serialized table */ - if(NULL == (buf = H5WB_actual(wb, 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, size, dxpl_id, buf) < 0) - HGOTO_ERROR(H5E_SOHM, H5E_READERROR, NULL, "can't read SOHM table") - /* Get temporary pointer to serialized table */ - p = buf; + p = image; /* Check magic number */ if(HDmemcmp(p, H5SM_TABLE_MAGIC, (size_t)H5SM_SIZEOF_MAGIC)) @@ -172,7 +165,7 @@ H5SM_table_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1 /* Don't count the checksum in the table size yet, since it comes after * all of the index headers */ - HDassert((size_t)(p - buf) == H5SM_TABLE_SIZE(f) - H5SM_SIZEOF_CHECKSUM); + HDassert((size_t)(p - (const uint8_t *)image) == H5SM_TABLE_SIZE(f) - H5SM_SIZEOF_CHECKSUM); /* Allocate space for the index headers in memory*/ if(NULL == (table->indexes = (H5SM_index_header_t *)H5FL_ARR_MALLOC(H5SM_index_header_t, (size_t)table->num_indexes))) @@ -213,10 +206,10 @@ H5SM_table_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1 UINT32DECODE(p, stored_chksum); /* Sanity check */ - HDassert((size_t)(p - buf) == size); + HDassert((size_t)(p - (const uint8_t *)image) == len); /* Compute checksum on entire header */ - computed_chksum = H5_checksum_metadata(buf, (size - H5SM_SIZEOF_CHECKSUM), 0); + computed_chksum = H5_checksum_metadata(image, (len - H5SM_SIZEOF_CHECKSUM), 0); /* Verify checksum */ if(stored_chksum != computed_chksum) @@ -225,283 +218,195 @@ H5SM_table_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1 /* Set return value */ ret_value = table; + /* Sanity check */ + HDassert((size_t)((const uint8_t *)p - (const uint8_t *)image) <= len); + done: /* Release resources */ - if(wb && H5WB_unwrap(wb) < 0) - HDONE_ERROR(H5E_SOHM, H5E_CLOSEERROR, NULL, "can't close wrapped buffer") - if(!ret_value && table) - (void)H5SM_table_dest(f, table); + if(!ret_value && table) + (void)H5SM_table_dest(table); FUNC_LEAVE_NOAPI(ret_value) -} /* end H5SM_table_load() */ +} /* end H5SM_table_deserialize() */ /*------------------------------------------------------------------------- - * Function: H5SM_table_flush + * Function: H5SM_table_serialize * - * Purpose: Flushes (and destroys) the table of Shared Object Header - * Message indexes. + * Purpose: Serialize the data structure for writing to disk. * - * Return: Non-negative on success/Negative on failure + * Return: Success: SUCCEED + * Failure: FAIL * * Programmer: James Laird * November 6, 2006 * + * Changes: Mike McGreevy + * mcgreevy@hdfgroup.org + * June 27, 2008 + * Converted from H5SM_table_flush() + * *------------------------------------------------------------------------- */ static herr_t -H5SM_table_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5SM_master_table_t *table) +H5SM_table_serialize(const H5F_t * f, haddr_t UNUSED addr, size_t UNUSED len, void *image, + void *_thing, unsigned *flags, haddr_t UNUSED *new_addr, + size_t UNUSED *new_len, void UNUSED **new_image) { - H5WB_t *wb = NULL; /* Wrapped buffer for table data */ - uint8_t tbl_buf[H5SM_TBL_BUF_SIZE]; /* Buffer for table */ + H5SM_master_table_t *table = (H5SM_master_table_t *)_thing; herr_t ret_value = SUCCEED; /* Return value */ + uint8_t *p; /* Pointer into raw data buffer */ + uint32_t computed_chksum; /* Computed metadata checksum value */ + size_t x; /* Counter variable */ - FUNC_ENTER_NOAPI_NOINIT(H5SM_table_flush) + FUNC_ENTER_NOAPI_NOINIT(H5SM_table_serialize) /* check arguments */ HDassert(f); - HDassert(H5F_addr_defined(addr)); + HDassert(image); HDassert(table); + HDassert(H5F_addr_defined(addr)); - if(table->cache_info.is_dirty) { - uint8_t *buf; /* Temporary buffer */ - uint8_t *p; /* Pointer into raw data buffer */ - size_t size; /* Header size on disk */ - uint32_t computed_chksum; /* Computed metadata checksum value */ - size_t x; /* Counter variable */ - - /* Verify that we're writing version 0 of the table; this is the only - * version defined so far. - */ - HDassert(f->shared->sohm_vers == HDF5_SHAREDHEADER_VERSION); - - /* Wrap the local buffer for serialized header info */ - if(NULL == (wb = H5WB_wrap(tbl_buf, sizeof(tbl_buf)))) - HGOTO_ERROR(H5E_SOHM, H5E_CANTINIT, FAIL, "can't wrap buffer") - - /* Encode the master table and all of the index headers as one big blob */ - size = H5SM_TABLE_SIZE(f) + (H5SM_INDEX_HEADER_SIZE(f) * table->num_indexes); - /* Get a pointer to a buffer that's large enough for serialized table */ - if(NULL == (buf = H5WB_actual(wb, size))) - HGOTO_ERROR(H5E_SOHM, H5E_NOSPACE, FAIL, "can't get actual buffer") + /* Verify that we're writing version 0 of the table; this is the only + * version defined so far. + */ + HDassert(f->shared->sohm_vers == HDF5_SHAREDHEADER_VERSION); - /* Get temporary pointer to buffer for serialized table */ - p = buf; + /* Get temporary pointer to buffer for serialized table */ + p = image; - /* Encode magic number */ - HDmemcpy(p, H5SM_TABLE_MAGIC, (size_t)H5SM_SIZEOF_MAGIC); - p += H5SM_SIZEOF_MAGIC; + /* Encode magic number */ + HDmemcpy(p, H5SM_TABLE_MAGIC, (size_t)H5SM_SIZEOF_MAGIC); + p += H5SM_SIZEOF_MAGIC; - /* Encode each index header */ - for(x = 0; x < table->num_indexes; ++x) { - /* Version for this list. */ - *p++ = H5SM_LIST_VERSION; + /* Encode each index header */ + for(x = 0; x < table->num_indexes; ++x) { + /* Version for this list. */ + *p++ = H5SM_LIST_VERSION; - /* Is message index a list or a B-tree? */ - *p++ = table->indexes[x].index_type; + /* Is message index a list or a B-tree? */ + *p++ = table->indexes[x].index_type; - /* Type of messages in the index */ - UINT16ENCODE(p, table->indexes[x].mesg_types); + /* Type of messages in the index */ + UINT16ENCODE(p, table->indexes[x].mesg_types); - /* Minimum size of message to share */ - UINT32ENCODE(p, table->indexes[x].min_mesg_size); + /* Minimum size of message to share */ + UINT32ENCODE(p, table->indexes[x].min_mesg_size); - /* List cutoff; fewer than this number and index becomes a list */ - UINT16ENCODE(p, table->indexes[x].list_max); + /* List cutoff; fewer than this number and index becomes a list */ + UINT16ENCODE(p, table->indexes[x].list_max); - /* B-tree cutoff; more than this number and index becomes a B-tree */ - UINT16ENCODE(p, table->indexes[x].btree_min); + /* B-tree cutoff; more than this number and index becomes a B-tree */ + UINT16ENCODE(p, table->indexes[x].btree_min); - /* Number of messages shared */ - UINT16ENCODE(p, table->indexes[x].num_messages); + /* Number of messages shared */ + UINT16ENCODE(p, table->indexes[x].num_messages); - /* Address of the actual index */ - H5F_addr_encode(f, &p, table->indexes[x].index_addr); + /* Address of the actual index */ + H5F_addr_encode(f, &p, table->indexes[x].index_addr); - /* Address of the index's heap */ - H5F_addr_encode(f, &p, table->indexes[x].heap_addr); - } /* end for */ + /* Address of the index's heap */ + H5F_addr_encode(f, &p, table->indexes[x].heap_addr); + } /* end for */ /* Compute checksum on buffer */ - computed_chksum = H5_checksum_metadata(buf, (size - H5SM_SIZEOF_CHECKSUM), 0); + computed_chksum = H5_checksum_metadata(image, (len - H5SM_SIZEOF_CHECKSUM), 0); UINT32ENCODE(p, computed_chksum); - /* Write the table to disk */ - HDassert((size_t)(p - buf) == size); - if(H5F_block_write(f, H5FD_MEM_SOHM_TABLE, addr, size, dxpl_id, buf) < 0) - HGOTO_ERROR(H5E_SOHM, H5E_CANTFLUSH, FAIL, "unable to save sohm table to disk") - - table->cache_info.is_dirty = FALSE; - } /* end if */ - - if(destroy) - if(H5SM_table_dest(f, table) < 0) - HGOTO_ERROR(H5E_SOHM, H5E_CANTFREE, FAIL, "unable to destroy sohm table") - -done: - /* Release resources */ - if(wb && H5WB_unwrap(wb) < 0) - HDONE_ERROR(H5E_SOHM, H5E_CLOSEERROR, FAIL, "can't close wrapped buffer") - - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5SM_table_flush() */ - - -/*------------------------------------------------------------------------- - * Function: H5SM_table_dest - * - * Purpose: Frees memory used by the SOHM table. - * - * Return: Non-negative on success/Negative on failure - * - * Programmer: James Laird - * November 6, 2006 - * - *------------------------------------------------------------------------- - */ -static herr_t -H5SM_table_dest(H5F_t UNUSED *f, H5SM_master_table_t* table) -{ - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5SM_table_dest) + /* Reset the cache flags for this operation (metadata not resize or renamed) */ + *flags = 0; /* Sanity check */ - HDassert(table); - HDassert(table->indexes); - - H5FL_ARR_FREE(H5SM_index_header_t, table->indexes); - - H5FL_FREE(H5SM_master_table_t, table); - - FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5SM_table_dest() */ - - -/*------------------------------------------------------------------------- - * Function: H5SM_table_clear - * - * Purpose: Mark this table as no longer being dirty. - * - * Return: Non-negative on success/Negative on failure - * - * Programmer: James Laird - * November 6, 2006 - * - *------------------------------------------------------------------------- - */ -static herr_t -H5SM_table_clear(H5F_t *f, H5SM_master_table_t *table, hbool_t destroy) -{ - herr_t ret_value = SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI_NOINIT(H5SM_table_clear) - - /* - * Check arguments. - */ - HDassert(table); - - /* Reset the dirty flag. */ - table->cache_info.is_dirty = FALSE; - - if(destroy) - if(H5SM_table_dest(f, table) < 0) - HGOTO_ERROR(H5E_SOHM, H5E_CANTFREE, FAIL, "unable to delete SOHM master table") + HDassert((size_t)((const uint8_t *)p - (const uint8_t *)image) <= len); done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5SM_table_clear() */ +} /* end H5SM_table_serialize() */ /*------------------------------------------------------------------------- - * Function: H5SM_table_size + * Function: H5SM_table_free_icr * - * Purpose: Returns the size of the table encoded on disk. + * Purpose: Destroy/release an "in core representation" of a data structure * - * Return: Non-negative on success/Negative on failure + * Return: Success: SUCCEED + * Failure: FAIL * - * Programmer: James Laird - * November 6, 2006 + * Programmer: Mike McGreevy + * mcgreevy@hdfgroup.org + * Jun 03, 2008 * *------------------------------------------------------------------------- */ static herr_t -H5SM_table_size(const H5F_t *f, const H5SM_master_table_t *table, size_t *size_ptr) +H5SM_table_free_icr(haddr_t UNUSED addr, size_t UNUSED len, void *thing) { - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5SM_table_size) - /* check arguments */ - HDassert(f); - HDassert(table); - HDassert(size_ptr); + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5SM_table_free_icr) - /* Set size value */ - *size_ptr = H5SM_TABLE_SIZE(f) + (table->num_indexes * H5SM_INDEX_HEADER_SIZE(f)); + /* Check arguments */ + HDassert(thing); + /* Destroy Shared Object Header Message */ + H5SM_table_dest(thing); + FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5SM_table_size() */ +} /* end H5SM_table_free_icr() */ /*------------------------------------------------------------------------- - * Function: H5SM_list_load + * Function: H5SM_list_deserialize * - * Purpose: Loads a list of SOHM messages. + * Purpose: Deserialize the data structure from disk. * - * Return: Non-negative on success/Negative on failure + * Return: Success: SUCCEED + * Failure: FAIL * * Programmer: James Laird * November 6, 2006 * + * Changes: Mike McGreevy + * mcgreevy@hdfgroup.org + * June 27, 2008 + * Converted from H5SM_list_load() + * *------------------------------------------------------------------------- */ -static H5SM_list_t * -H5SM_list_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1, void *udata2) +static void * +H5SM_list_deserialize(haddr_t UNUSED addr, size_t UNUSED len, const void *image, + const void *_udata, hbool_t UNUSED *dirty) { H5SM_list_t *list; /* The SOHM list being read in */ - H5SM_index_header_t *header = (H5SM_index_header_t *) udata2; /* Index header for this list */ + const H5SM_list_cache_ud_t *udata = (const H5SM_list_cache_ud_t *)_udata; /* User data for callback */ size_t size; /* Size of SOHM list on disk */ - H5WB_t *wb = NULL; /* Wrapped buffer for list index data */ - uint8_t lst_buf[H5SM_LST_BUF_SIZE]; /* Buffer for list index */ - uint8_t *buf; /* Reading buffer */ uint8_t *p; /* Pointer into input buffer */ uint32_t stored_chksum; /* Stored metadata checksum value */ uint32_t computed_chksum; /* Computed metadata checksum value */ size_t x; /* Counter variable for messages in list */ H5SM_list_t *ret_value; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT(H5SM_list_load) + FUNC_ENTER_NOAPI_NOINIT(H5SM_list_deserialize) /* Sanity check */ - HDassert(header); + HDassert(udata->header); /* Allocate space for the SOHM list data structure */ if(NULL == (list = H5FL_MALLOC(H5SM_list_t))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - HDmemset(&list->cache_info, 0, sizeof(H5AC_info_t)); + HDmemset(&list->cache_info, 0, sizeof(H5AC2_info_t)); /* Allocate list in memory as an array*/ - if((list->messages = (H5SM_sohm_t *)H5FL_ARR_MALLOC(H5SM_sohm_t, header->list_max)) == NULL) + if((list->messages = (H5SM_sohm_t *)H5FL_ARR_MALLOC(H5SM_sohm_t, udata->header->list_max)) == NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "file allocation failed for SOHM list") - list->header = header; - - /* Wrap the local buffer for serialized list index info */ - if(NULL == (wb = H5WB_wrap(lst_buf, sizeof(lst_buf)))) - HGOTO_ERROR(H5E_SOHM, H5E_CANTINIT, NULL, "can't wrap buffer") + list->header = udata->header; /* Compute the size of the SOHM list on disk */ - size = H5SM_LIST_SIZE(f, header->num_messages); - - /* Get a pointer to a buffer that's large enough for serialized list index */ - if(NULL == (buf = H5WB_actual(wb, 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, size, dxpl_id, buf) < 0) - HGOTO_ERROR(H5E_SOHM, H5E_READERROR, NULL, "can't read SOHM list") + size = H5SM_LIST_SIZE(udata->f, udata->header->num_messages); /* Get temporary pointer to serialized list index */ - p = buf; + p = image; /* Check magic number */ if(HDmemcmp(p, H5SM_LIST_MAGIC, (size_t)H5SM_SIZEOF_MAGIC)) @@ -509,36 +414,37 @@ H5SM_list_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1, p += H5SM_SIZEOF_MAGIC; /* Read messages into the list array */ - for(x = 0; x < header->num_messages; x++) { - if(H5SM_message_decode(f, p, &(list->messages[x])) < 0) + for(x = 0; x < udata->header->num_messages; x++) { + if(H5SM_message_decode(udata->f, p, &(list->messages[x])) < 0) HGOTO_ERROR(H5E_SOHM, H5E_CANTLOAD, NULL, "can't decode shared message") - p += H5SM_SOHM_ENTRY_SIZE(f); + p += H5SM_SOHM_ENTRY_SIZE(udata->f); } /* end for */ /* Read in checksum */ UINT32DECODE(p, stored_chksum); /* Sanity check */ - HDassert((size_t)(p - buf) == size); + HDassert((size_t)(p - (const uint8_t *)image) == size); /* Compute checksum on entire header */ - computed_chksum = H5_checksum_metadata(buf, (size - H5SM_SIZEOF_CHECKSUM), 0); + computed_chksum = H5_checksum_metadata(image, (size - H5SM_SIZEOF_CHECKSUM), 0); /* Verify checksum */ if(stored_chksum != computed_chksum) HGOTO_ERROR(H5E_SOHM, H5E_BADVALUE, NULL, "incorrect metadata checksum for shared message list") /* Initialize the rest of the array */ - for(x = header->num_messages; x < header->list_max; x++) + for(x = udata->header->num_messages; x < udata->header->list_max; x++) list->messages[x].location = H5SM_NO_LOC; /* Set return value */ ret_value = list; + /* Sanity check */ + HDassert((size_t)((const uint8_t *)p - (const uint8_t *)image) <= len); + done: /* Release resources */ - if(wb && H5WB_unwrap(wb) < 0) - HDONE_ERROR(H5E_SOHM, H5E_CLOSEERROR, NULL, "can't close wrapped buffer") if(!ret_value && list) { if(list->messages) H5FL_ARR_FREE(H5SM_sohm_t, list->messages); @@ -546,189 +452,110 @@ done: } /* end if */ FUNC_LEAVE_NOAPI(ret_value) -} /* end H5SM_list_load() */ +} /* end H5SM_list_deserialize() */ /*------------------------------------------------------------------------- - * Function: H5SM_list_flush + * Function: H5SM_list_serialize * - * Purpose: Flush this list index. + * Purpose: Serialize the data structure for writing to disk. * - * Return: Non-negative on success/Negative on failure + * Return: Success: SUCCEED + * Failure: FAIL * * Programmer: James Laird * November 6, 2006 * + * Changes: Mike McGreevy + * mcgreevy@hdfgroup.org + * June 27, 2008 + * Converted from H5SM_list_flush() + * *------------------------------------------------------------------------- */ static herr_t -H5SM_list_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5SM_list_t *list) +H5SM_list_serialize(const H5F_t * f, haddr_t UNUSED addr, size_t UNUSED len, void *image, + void *_thing, unsigned *flags, haddr_t UNUSED *new_addr, + size_t UNUSED *new_len, void UNUSED **new_image) { - H5WB_t *wb = NULL; /* Wrapped buffer for list index data */ - uint8_t lst_buf[H5SM_LST_BUF_SIZE]; /* Buffer for list index */ + H5SM_list_t *list = (H5SM_list_t *)_thing; herr_t ret_value = SUCCEED; /* Return value */ + uint8_t *p; /* Pointer into raw data buffer */ + size_t size; /* Header size on disk */ + uint32_t computed_chksum; /* Computed metadata checksum value */ + size_t mesgs_written; /* Number of messages written to list */ + size_t x; /* Local index variable */ - FUNC_ENTER_NOAPI_NOINIT(H5SM_list_flush) + FUNC_ENTER_NOAPI_NOINIT(H5SM_list_serialize) /* check arguments */ HDassert(f); - HDassert(H5F_addr_defined(addr)); + HDassert(image); HDassert(list); HDassert(list->header); - if(list->cache_info.is_dirty) { - uint8_t *buf; /* Temporary buffer */ - uint8_t *p; /* Pointer into raw data buffer */ - size_t size; /* Header size on disk */ - uint32_t computed_chksum; /* Computed metadata checksum value */ - size_t mesgs_written; /* Number of messages written to list */ - size_t x; /* Local index variable */ - - /* Wrap the local buffer for serialized list index info */ - if(NULL == (wb = H5WB_wrap(lst_buf, sizeof(lst_buf)))) - HGOTO_ERROR(H5E_SOHM, H5E_CANTINIT, FAIL, "can't wrap buffer") - - size = H5SM_LIST_SIZE(f, list->header->num_messages); - - /* Get a pointer to a buffer that's large enough for serialized list index */ - if(NULL == (buf = H5WB_actual(wb, size))) - HGOTO_ERROR(H5E_SOHM, H5E_NOSPACE, FAIL, "can't get actual buffer") - - /* Get temporary pointer to buffer for serialized list index */ - p = buf; - - /* Encode magic number */ - HDmemcpy(p, H5SM_LIST_MAGIC, (size_t)H5SM_SIZEOF_MAGIC); - p += H5SM_SIZEOF_MAGIC; + size = H5SM_LIST_SIZE(f, list->header->num_messages); - /* Write messages from the messages array to disk */ - mesgs_written = 0; - for(x = 0; x < list->header->list_max && mesgs_written < list->header->num_messages; x++) { - if(list->messages[x].location != H5SM_NO_LOC) { - if(H5SM_message_encode(f, p, &(list->messages[x])) < 0) - HGOTO_ERROR(H5E_SOHM, H5E_CANTFLUSH, FAIL, "unable to write shared message to disk") + /* Get temporary pointer to buffer for serialized list index */ + p = image; - p+=H5SM_SOHM_ENTRY_SIZE(f); - ++mesgs_written; - } /* end if */ - } /* end for */ - HDassert(mesgs_written == list->header->num_messages); - - /* Compute checksum on buffer */ - computed_chksum = H5_checksum_metadata(buf, (size - H5SM_SIZEOF_CHECKSUM), 0); - UINT32ENCODE(p, computed_chksum); - - /* Write the list to disk */ - HDassert((size_t)(p - buf) == size); - if(H5F_block_write(f, H5FD_MEM_SOHM_INDEX, addr, size, dxpl_id, buf) < 0) - HGOTO_ERROR(H5E_SOHM, H5E_CANTFLUSH, FAIL, "unable to save sohm table to disk") - - list->cache_info.is_dirty = FALSE; - } /* end if */ - - if(destroy) - if(H5SM_list_dest(f, list) < 0) - HGOTO_ERROR(H5E_SOHM, H5E_CANTFREE, FAIL, "unable to destroy list") - -done: - /* Release resources */ - if(wb && H5WB_unwrap(wb) < 0) - HDONE_ERROR(H5E_SOHM, H5E_CLOSEERROR, FAIL, "can't close wrapped buffer") - - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5SM_list_flush() */ - - -/*------------------------------------------------------------------------- - * Function: H5SM_list_dest - * - * Purpose: Frees all memory used by the list. - * - * Return: Non-negative on success/Negative on failure - * - * Programmer: James Laird - * November 6, 2006 - * - *------------------------------------------------------------------------- - */ -static herr_t -H5SM_list_dest(H5F_t UNUSED *f, H5SM_list_t* list) -{ - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5SM_list_dest) - - HDassert(list); - HDassert(list->messages); - - H5FL_ARR_FREE(H5SM_sohm_t, list->messages); - - H5FL_FREE(H5SM_list_t, list); + /* Encode magic number */ + HDmemcpy(p, H5SM_LIST_MAGIC, (size_t)H5SM_SIZEOF_MAGIC); + p += H5SM_SIZEOF_MAGIC; - FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5SM_list_dest() */ + /* Write messages from the messages array to disk */ + mesgs_written = 0; + for(x = 0; x < list->header->list_max && mesgs_written < list->header->num_messages; x++) { + if(list->messages[x].location != H5SM_NO_LOC) { + if(H5SM_message_encode(f, p, &(list->messages[x])) < 0) + HGOTO_ERROR(H5E_SOHM, H5E_CANTFLUSH, FAIL, "unable to write shared message to disk") - -/*------------------------------------------------------------------------- - * Function: H5SM_list_clear - * - * Purpose: Marks a list as not dirty. - * - * Return: Non-negative on success/Negative on failure - * - * Programmer: James Laird - * November 6, 2006 - * - *------------------------------------------------------------------------- - */ -static herr_t -H5SM_list_clear(H5F_t *f, H5SM_list_t *list, hbool_t destroy) -{ - herr_t ret_value = SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI_NOINIT(H5SM_list_clear) + p+=H5SM_SOHM_ENTRY_SIZE(f); + ++mesgs_written; + } /* end if */ + } /* end for */ + HDassert(mesgs_written == list->header->num_messages); - /* - * Check arguments. - */ - HDassert(list); + /* Compute checksum on buffer */ + computed_chksum = H5_checksum_metadata(image, (size - H5SM_SIZEOF_CHECKSUM), 0); + UINT32ENCODE(p, computed_chksum); - /* Reset the dirty flag. */ - list->cache_info.is_dirty = FALSE; + /* Reset the cache flags for this operation (metadata not resize or renamed) */ + *flags = 0; - if(destroy) - if(H5SM_list_dest(f, list) < 0) - HGOTO_ERROR(H5E_SOHM, H5E_CANTFREE, FAIL, "unable to destroy SOHM list") + /* Sanity check */ + HDassert((size_t)((const uint8_t *)p - (const uint8_t *)image) <= len); done: FUNC_LEAVE_NOAPI(ret_value) -} /* end of H5SM_list_clear() */ +} /* end H5SM_list_serialize() */ /*------------------------------------------------------------------------- - * Function: H5SM_list_size + * Function: H5SM_list_free_icr * - * Purpose: Gets the size of a list on disk. + * Purpose: Destroy/release an "in core representation" of a data structure * - * Return: Non-negative on success/Negative on failure + * Return: Success: SUCCEED + * Failure: FAIL * - * Programmer: James Laird - * November 6, 2006 + * Programmer: Mike McGreevy + * mcgreevy@hdfgroup.org + * Jun 03, 2008 * *------------------------------------------------------------------------- */ static herr_t -H5SM_list_size(const H5F_t UNUSED *f, const H5SM_list_t *list, size_t *size_ptr) +H5SM_list_free_icr(haddr_t UNUSED addr, size_t UNUSED len, void *thing) { - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5SM_list_size) - /* check arguments */ - HDassert(f); - HDassert(list); - HDassert(list->header); - HDassert(size_ptr); + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5SM_list_free_icr) - /* Set size value */ - *size_ptr = H5SM_LIST_SIZE(f, list->header->list_max); + /* Check arguments */ + HDassert(thing); + /* Destroy Shared Object Header Message */ + H5SM_list_dest(thing); + FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5SM_list_size() */ - +} /* end H5SM_list_free_icr() */ diff --git a/src/H5SMpkg.h b/src/H5SMpkg.h index 0643ebb..7af60f6 100755 --- a/src/H5SMpkg.h +++ b/src/H5SMpkg.h @@ -32,7 +32,7 @@ #include "H5SMprivate.h" /* Shared Object Header Messages */ /* Other private headers needed by this file */ -#include "H5ACprivate.h" /* Metadata cache */ +#include "H5AC2private.h" /* Metadata Cache */ #include "H5B2private.h" /* B-trees */ #include "H5HFprivate.h" /* Fractal heaps */ @@ -174,7 +174,7 @@ typedef struct { /* Typedef for a SOHM list */ typedef struct { /* Information for H5AC cache functions, _must_ be first field in structure */ - H5AC_info_t cache_info; + H5AC2_info_t cache_info; H5SM_index_header_t *header; /* Pointer to the corresponding index header */ H5SM_sohm_t *messages; /* Actual list, stored as an array */ @@ -184,7 +184,7 @@ typedef struct { /* Typedef for shared object header message master table */ struct H5SM_master_table_t { /* Information for H5AC cache functions, _must_ be first field in structure */ - H5AC_info_t cache_info; + H5AC2_info_t cache_info; unsigned num_indexes; /* Number of indexes */ H5SM_index_header_t *indexes; /* Array of num_indexes indexes */ @@ -221,6 +221,12 @@ typedef struct { hid_t dxpl_id; } H5SM_incr_ref_opdata; +/* Callback info for loading a shared message index into the cache */ +typedef struct H5SM_list_cache_ud_t { + H5F_t *f; /* File that shared message index stored as a list is in */ + H5SM_index_header_t *header; /* Index header for this list */ +} H5SM_list_cache_ud_t; + /****************************/ /* Package Variables */ @@ -232,8 +238,8 @@ H5FL_ARR_EXTERN(H5SM_index_header_t); H5FL_EXTERN(H5SM_list_t); H5FL_ARR_EXTERN(H5SM_sohm_t); -H5_DLLVAR const H5AC_class_t H5AC_SOHM_TABLE[1]; -H5_DLLVAR const H5AC_class_t H5AC_SOHM_LIST[1]; +H5_DLLVAR const H5AC2_class_t H5AC2_SOHM_TABLE[1]; +H5_DLLVAR const H5AC2_class_t H5AC2_SOHM_LIST[1]; H5_DLLVAR const H5B2_class_t H5SM_INDEX[1]; /****************************/ @@ -262,6 +268,10 @@ H5_DLL herr_t H5SM_btree_convert_to_list_op(const void * record, void *op_data); /* Fractal heap 'op' callback to compute hash value for message "in place" */ H5_DLL herr_t H5SM_get_hash_fh_cb(const void *obj, size_t obj_len, void *_udata); +herr_t H5SM_table_dest(H5SM_master_table_t * table); + +herr_t H5SM_list_dest(H5SM_list_t * list); + /* Testing functions */ #ifdef H5SM_TESTING H5_DLL herr_t H5SM_get_mesg_count_test(H5F_t *f, hid_t dxpl_id, unsigned type_id, diff --git a/src/H5SMtest.c b/src/H5SMtest.c index 5de8ce1..dc19287 100644 --- a/src/H5SMtest.c +++ b/src/H5SMtest.c @@ -81,6 +81,7 @@ H5SM_get_mesg_count_test(H5F_t *f, hid_t dxpl_id, unsigned type_id, { H5SM_master_table_t *table = NULL; /* SOHM master table */ herr_t ret_value = SUCCEED; /* Return value */ + hsize_t table_size; /* Size of SOHM master table in file */ FUNC_ENTER_NOAPI_NOINIT(H5SM_get_mesg_count_test) @@ -93,8 +94,11 @@ H5SM_get_mesg_count_test(H5F_t *f, hid_t dxpl_id, unsigned type_id, H5SM_index_header_t *header; /* Index header for message type */ ssize_t index_num; /* Table index for message type */ + /* Determine size of table in file */ + table_size = (hsize_t) H5SM_TABLE_SIZE(f) + (hsize_t)(f->shared->sohm_nindexes * H5SM_INDEX_HEADER_SIZE(f)); + /* Look up the master SOHM table */ - if(NULL == (table = (H5SM_master_table_t *)H5AC_protect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, NULL, NULL, H5AC_READ))) + if(NULL == (table = (H5SM_master_table_t *)H5AC2_protect(f, dxpl_id, H5AC2_SOHM_TABLE, f->shared->sohm_addr, (size_t)table_size, f, H5AC2_READ))) HGOTO_ERROR(H5E_CACHE, H5E_CANTPROTECT, FAIL, "unable to load SOHM master table") /* Find the correct index for this message type */ @@ -111,7 +115,7 @@ H5SM_get_mesg_count_test(H5F_t *f, hid_t dxpl_id, unsigned type_id, done: /* Release resources */ - if(table && H5AC_unprotect(f, dxpl_id, H5AC_SOHM_TABLE, f->shared->sohm_addr, table, H5AC__NO_FLAGS_SET) < 0) + if(table && H5AC2_unprotect(f, dxpl_id, H5AC2_SOHM_TABLE, f->shared->sohm_addr, (size_t)0, table, H5AC2__NO_FLAGS_SET) < 0) HDONE_ERROR(H5E_CACHE, H5E_CANTRELEASE, FAIL, "unable to close SOHM master table") FUNC_LEAVE_NOAPI(ret_value) |