diff options
Diffstat (limited to 'src/H5SMcache.c')
-rw-r--r-- | src/H5SMcache.c | 79 |
1 files changed, 51 insertions, 28 deletions
diff --git a/src/H5SMcache.c b/src/H5SMcache.c index 7c6cdfc..070b00e 100644 --- a/src/H5SMcache.c +++ b/src/H5SMcache.c @@ -27,6 +27,7 @@ #include "H5Eprivate.h" /* Error handling */ #include "H5Fpkg.h" /* File access */ #include "H5FLprivate.h" /* Free Lists */ +#include "H5MFprivate.h" /* File memory management */ #include "H5MMprivate.h" /* Memory management */ #include "H5SMpkg.h" /* Shared object header messages */ #include "H5WBprivate.h" /* Wrapped Buffers */ @@ -75,6 +76,7 @@ const H5AC_class_t H5AC_SOHM_TABLE[1] = {{ (H5AC_flush_func_t)H5SM_table_flush, (H5AC_dest_func_t)H5SM_table_dest, (H5AC_clear_func_t)H5SM_table_clear, + (H5AC_notify_func_t)NULL, (H5AC_size_func_t)H5SM_table_size, }}; @@ -84,6 +86,7 @@ const H5AC_class_t H5AC_SOHM_LIST[1] = {{ (H5AC_flush_func_t)H5SM_list_flush, (H5AC_dest_func_t)H5SM_list_dest, (H5AC_clear_func_t)H5SM_list_clear, + (H5AC_notify_func_t)NULL, (H5AC_size_func_t)H5SM_list_size, }}; @@ -135,7 +138,7 @@ H5SM_table_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1 /* Allocate space for the master table in memory */ if(NULL == (table = H5FL_CALLOC(H5SM_master_table_t))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + HGOTO_ERROR(H5E_SOHM, H5E_NOSPACE, NULL, "memory allocation failed") /* Read number of indexes and version from file superblock */ table->num_indexes = f->shared->sohm_nindexes; @@ -154,7 +157,7 @@ H5SM_table_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1 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))) + if(NULL == (buf = (uint8_t *)H5WB_actual(wb, size))) HGOTO_ERROR(H5E_SOHM, H5E_NOSPACE, NULL, "can't get actual buffer") /* Read header from disk */ @@ -165,9 +168,9 @@ H5SM_table_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1 p = buf; /* Check magic number */ - if(HDmemcmp(p, H5SM_TABLE_MAGIC, (size_t)H5SM_SIZEOF_MAGIC)) + if(HDmemcmp(p, H5SM_TABLE_MAGIC, (size_t)H5_SIZEOF_MAGIC)) HGOTO_ERROR(H5E_SOHM, H5E_CANTLOAD, NULL, "bad SOHM table signature") - p += H5SM_SIZEOF_MAGIC; + p += H5_SIZEOF_MAGIC; /* Don't count the checksum in the table size yet, since it comes after * all of the index headers @@ -176,16 +179,16 @@ H5SM_table_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1 /* 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))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for SOHM indexes") + HGOTO_ERROR(H5E_SOHM, H5E_NOSPACE, NULL, "memory allocation failed for SOHM indexes") /* Read in the index headers */ for(x = 0; x < table->num_indexes; ++x) { /* Verify correct version of index list */ if(H5SM_LIST_VERSION != *p++) - HGOTO_ERROR(H5E_FILE, H5E_VERSION, NULL, "bad shared message list version number") + HGOTO_ERROR(H5E_SOHM, H5E_VERSION, NULL, "bad shared message list version number") /* Type of the index (list or B-tree) */ - table->indexes[x].index_type= *p++; + table->indexes[x].index_type= (H5SM_index_type_t)*p++; /* Type of messages in the index */ UINT16DECODE(p, table->indexes[x].mesg_types); @@ -233,7 +236,7 @@ done: (void)H5SM_table_dest(f, table); FUNC_LEAVE_NOAPI(ret_value) -} /* end H5SM_table_load() */ +} /* end H5SM_table_load() */ /*------------------------------------------------------------------------- @@ -283,15 +286,15 @@ H5SM_table_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5SM_ma 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))) + if(NULL == (buf = (uint8_t *)H5WB_actual(wb, size))) HGOTO_ERROR(H5E_SOHM, H5E_NOSPACE, FAIL, "can't get actual buffer") /* Get temporary pointer to buffer for serialized table */ p = buf; /* Encode magic number */ - HDmemcpy(p, H5SM_TABLE_MAGIC, (size_t)H5SM_SIZEOF_MAGIC); - p += H5SM_SIZEOF_MAGIC; + HDmemcpy(p, H5SM_TABLE_MAGIC, (size_t)H5_SIZEOF_MAGIC); + p += H5_SIZEOF_MAGIC; /* Encode each index header */ for(x = 0; x < table->num_indexes; ++x) { @@ -371,7 +374,7 @@ H5SM_table_dest(H5F_t UNUSED *f, H5SM_master_table_t* table) H5FL_ARR_FREE(H5SM_index_header_t, table->indexes); - H5FL_FREE(H5SM_master_table_t, table); + (void)H5FL_FREE(H5SM_master_table_t, table); FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5SM_table_dest() */ @@ -459,6 +462,7 @@ H5SM_list_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1, { 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 */ + H5SM_bt2_ctx_t ctx; /* Message encoding context */ 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 */ @@ -476,12 +480,12 @@ H5SM_list_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1, /* 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") + HGOTO_ERROR(H5E_SOHM, H5E_NOSPACE, NULL, "memory allocation failed") HDmemset(&list->cache_info, 0, sizeof(H5AC_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) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "file allocation failed for SOHM list") + HGOTO_ERROR(H5E_SOHM, H5E_NOSPACE, NULL, "file allocation failed for SOHM list") list->header = header; @@ -493,7 +497,7 @@ H5SM_list_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1, 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))) + if(NULL == (buf = (uint8_t *)H5WB_actual(wb, size))) HGOTO_ERROR(H5E_SOHM, H5E_NOSPACE, NULL, "can't get actual buffer") /* Read list from disk */ @@ -504,13 +508,14 @@ H5SM_list_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1, p = buf; /* Check magic number */ - if(HDmemcmp(p, H5SM_LIST_MAGIC, (size_t)H5SM_SIZEOF_MAGIC)) + if(HDmemcmp(p, H5SM_LIST_MAGIC, (size_t)H5_SIZEOF_MAGIC)) HGOTO_ERROR(H5E_SOHM, H5E_CANTLOAD, NULL, "bad SOHM list signature") - p += H5SM_SIZEOF_MAGIC; + p += H5_SIZEOF_MAGIC; /* Read messages into the list array */ + ctx.sizeof_addr = H5F_SIZEOF_ADDR(f); for(x = 0; x < header->num_messages; x++) { - if(H5SM_message_decode(f, p, &(list->messages[x])) < 0) + if(H5SM_message_decode(p, &(list->messages[x]), &ctx) < 0) HGOTO_ERROR(H5E_SOHM, H5E_CANTLOAD, NULL, "can't decode shared message") p += H5SM_SOHM_ENTRY_SIZE(f); } /* end for */ @@ -542,7 +547,7 @@ done: if(!ret_value && list) { if(list->messages) H5FL_ARR_FREE(H5SM_sohm_t, list->messages); - H5FL_FREE(H5SM_list_t, list); + (void)H5FL_FREE(H5SM_list_t, list); } /* end if */ FUNC_LEAVE_NOAPI(ret_value) @@ -577,6 +582,7 @@ H5SM_list_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5SM_lis HDassert(list->header); if(list->cache_info.is_dirty) { + H5SM_bt2_ctx_t ctx; /* Message encoding context */ uint8_t *buf; /* Temporary buffer */ uint8_t *p; /* Pointer into raw data buffer */ size_t size; /* Header size on disk */ @@ -591,21 +597,22 @@ H5SM_list_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5SM_lis 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))) + if(NULL == (buf = (uint8_t *)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; + HDmemcpy(p, H5SM_LIST_MAGIC, (size_t)H5_SIZEOF_MAGIC); + p += H5_SIZEOF_MAGIC; /* Write messages from the messages array to disk */ mesgs_written = 0; + ctx.sizeof_addr = H5F_SIZEOF_ADDR(f); 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) + if(H5SM_message_encode(p, &(list->messages[x]), &ctx) < 0) HGOTO_ERROR(H5E_SOHM, H5E_CANTFLUSH, FAIL, "unable to write shared message to disk") p+=H5SM_SOHM_ENTRY_SIZE(f); @@ -652,18 +659,34 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5SM_list_dest(H5F_t UNUSED *f, H5SM_list_t* list) +H5SM_list_dest(H5F_t *f, H5SM_list_t* list) { - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5SM_list_dest) + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT(H5SM_list_dest) + /* Sanity check */ HDassert(list); + HDassert(list->header); HDassert(list->messages); - H5FL_ARR_FREE(H5SM_sohm_t, list->messages); + /* If we're going to free the space on disk, the address must be valid */ + HDassert(!list->cache_info.free_file_space_on_destroy || H5F_addr_defined(list->cache_info.addr)); + + /* Check for freeing file space for shared message index list */ + if(list->cache_info.free_file_space_on_destroy) { + /* Release the space on disk */ + /* (XXX: Nasty usage of internal DXPL value! -QAK) */ + if(H5MF_xfree(f, H5FD_MEM_SOHM_INDEX, H5AC_dxpl_id, list->cache_info.addr, (hsize_t)H5SM_LIST_SIZE(f, list->header->list_max)) < 0) + HGOTO_ERROR(H5E_SOHM, H5E_NOSPACE, FAIL, "unable to free shared message list") + } /* end if */ - H5FL_FREE(H5SM_list_t, list); + /* Release resources */ + H5FL_ARR_FREE(H5SM_sohm_t, list->messages); + (void)H5FL_FREE(H5SM_list_t, list); - FUNC_LEAVE_NOAPI(SUCCEED) +done: + FUNC_LEAVE_NOAPI(ret_value) } /* end H5SM_list_dest() */ |