summaryrefslogtreecommitdiffstats
path: root/src/H5SMcache.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5SMcache.c')
-rw-r--r--src/H5SMcache.c652
1 files changed, 358 insertions, 294 deletions
diff --git a/src/H5SMcache.c b/src/H5SMcache.c
index 3b85bcf..371344a 100644
--- a/src/H5SMcache.c
+++ b/src/H5SMcache.c
@@ -17,8 +17,9 @@
/* Module Setup */
/****************/
-#define H5SM_PACKAGE /*suppress error about including H5SMpkg */
#define H5F_PACKAGE /*suppress error about including H5Fpkg */
+#define H5SM_PACKAGE /*suppress error about including H5SMpkg */
+
/***********/
/* Headers */
@@ -28,157 +29,78 @@
#include "H5FLprivate.h" /* Free Lists */
#include "H5MMprivate.h" /* Memory management */
#include "H5SMpkg.h" /* Shared object header messages */
+#include "H5WBprivate.h" /* Wrapped Buffers */
+
/****************/
/* Local Macros */
/****************/
+/* Size of stack buffer for serialized tables */
+#define H5SM_TBL_BUF_SIZE 1024
+
+/* Size of stack buffer for serialized list indices */
+#define H5SM_LST_BUF_SIZE 1024
+
+
/******************/
/* Local Typedefs */
/******************/
+
/********************/
/* Local Prototypes */
/********************/
-static herr_t H5SM_flush_table(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5SM_master_table_t *table);
-static H5SM_master_table_t *H5SM_load_table(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *udata1, void *table);
-static herr_t H5SM_clear_table(H5F_t *f, H5SM_master_table_t *table, hbool_t destroy);
-static herr_t H5SM_dest_table(H5F_t *f, H5SM_master_table_t* table);
-static herr_t H5SM_table_size(const H5F_t *f, const H5SM_master_table_t *table, size_t *size_ptr);
-static herr_t H5SM_flush_list(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5SM_list_t *list);
-static H5SM_list_t *H5SM_load_list(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *udata1, void *udata2);
-static herr_t H5SM_clear_list(H5F_t *f, H5SM_list_t *list, hbool_t destroy);
-static herr_t H5SM_dest_list(H5F_t *f, H5SM_list_t* list);
+/* 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);
+
/*********************/
/* 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_load_table,
- (H5AC_flush_func_t) H5SM_flush_table,
- (H5AC_dest_func_t) H5SM_dest_table,
- (H5AC_clear_func_t)H5SM_clear_table,
- (H5AC_size_func_t) H5SM_table_size,
+ (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,
}};
const H5AC_class_t H5AC_SOHM_LIST[1] = {{
- H5AC_SOHM_LIST_ID,
- (H5AC_load_func_t) H5SM_load_list,
- (H5AC_flush_func_t) H5SM_flush_list,
- (H5AC_dest_func_t) H5SM_dest_list,
- (H5AC_clear_func_t)H5SM_clear_list,
- (H5AC_size_func_t) H5SM_list_size,
+ 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,
}};
-/* Declare a free list to manage data to/from disk */
-H5FL_BLK_DEFINE_STATIC(shared_mesg_cache);
/*****************************/
/* Library Private Variables */
/*****************************/
+
/*******************/
/* Local Variables */
/*******************/
-/*-------------------------------------------------------------------------
- * Function: H5SM_flush_table
- *
- * Purpose: Flushes (and destroys) the table of Shared Object Header
- * Message indexes.
- *
- * Return: Non-negative on success/Negative on failure
- *
- * Programmer: James Laird
- * November 6, 2006
- *
- *-------------------------------------------------------------------------
- */
-static herr_t
-H5SM_flush_table(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5SM_master_table_t *table)
-{
- uint8_t *buf=NULL; /* Temporary buffer */
- herr_t ret_value=SUCCEED;
-
- FUNC_ENTER_NOAPI_NOINIT(H5SM_flush_table)
-
- /* check arguments */
- HDassert(f);
- HDassert(H5F_addr_defined(addr));
- HDassert(table);
-
- if(table->cache_info.is_dirty) {
- uint8_t *p; /* Pointer into raw data buffer */
- size_t size; /* Header size on disk */
- uint32_t computed_chksum; /* Computed metadata checksum value */
- int 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);
-
- /* 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);
-
- /* Allocate the buffer */
- if(NULL == (buf = H5FL_BLK_MALLOC(shared_mesg_cache, size)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
-
- /* Encode the master table */
- p = buf;
-
- /* Encode magic number */
- HDmemcpy(p, H5SM_TABLE_MAGIC, (size_t)H5SM_TABLE_SIZEOF_MAGIC);
- p += H5SM_TABLE_SIZEOF_MAGIC;
-
- /* Encode each index header */
- for(x=0; x<table->num_indexes; ++x) {
- *p++ = H5SM_LIST_VERSION; /* Encode version for this list. */
- *p++ = table->indexes[x].index_type; /* Is message index a list or a B-tree? */
-
- UINT16ENCODE(p, table->indexes[x].mesg_types); /* Type of messages in the index */
- UINT32ENCODE(p, table->indexes[x].min_mesg_size); /* Minimum size of message to share */
- UINT16ENCODE(p, table->indexes[x].list_max); /* List cutoff; fewer than this number and index becomes a list */
- 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].num_messages); /* Number of messages shared */
- H5F_addr_encode(f, &p, table->indexes[x].index_addr); /* Address of the actual index */
- H5F_addr_encode(f, &p, table->indexes[x].heap_addr); /* Address of the index's heap */
- }
-
- /* Compute checksum on buffer */
- computed_chksum = H5_checksum_metadata(buf, (size - 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_dest_table(f, table) < 0)
- HGOTO_ERROR(H5E_SOHM, H5E_CANTFREE, FAIL, "unable to destroy sohm table")
-
-done:
- /* Free buffer if allocated */
- if(buf)
- buf = H5FL_BLK_FREE(shared_mesg_cache, buf);
-
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5SM_flush_table */
-
/*-------------------------------------------------------------------------
- * Function: H5SM_load_table
+ * Function: H5SM_table_load
*
* Purpose: Loads the master table of Shared Object Header Message
* indexes.
@@ -191,22 +113,24 @@ done:
*-------------------------------------------------------------------------
*/
static H5SM_master_table_t *
-H5SM_load_table(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1, void UNUSED *udata2)
+H5SM_table_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1, void UNUSED *udata2)
{
H5SM_master_table_t *table = NULL;
- size_t table_size; /* Size of SOHM master table on disk */
- uint8_t *buf=NULL; /* Reading buffer */
- const uint8_t *p; /* Pointer into input buffer */
- uint32_t stored_chksum; /* Stored metadata checksum value */
- uint32_t computed_chksum; /* Computed metadata checksum value */
- uint8_t x; /* Counter variable for index headers */
+ 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 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_load_table)
+ FUNC_ENTER_NOAPI_NOINIT(H5SM_table_load)
/* Verify that we're reading version 0 of the table; this is the only
- * version defined so far.
- */
+ * version defined so far.
+ */
HDassert(f->shared->sohm_vers == HDF5_SHAREDHEADER_VERSION);
/* Allocate space for the master table in memory */
@@ -220,25 +144,30 @@ H5SM_load_table(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
*/
- table_size = H5SM_TABLE_SIZE(f) + (table->num_indexes * H5SM_INDEX_HEADER_SIZE(f));
+ size = H5SM_TABLE_SIZE(f) + (table->num_indexes * H5SM_INDEX_HEADER_SIZE(f));
- /* Allocate temporary buffer */
- if(NULL == (buf = H5FL_BLK_MALLOC(shared_mesg_cache, table_size)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
+ /* 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, table_size, dxpl_id, buf) < 0)
+ 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;
/* Check magic number */
- if(HDmemcmp(p, H5SM_TABLE_MAGIC, (size_t)H5SM_TABLE_SIZEOF_MAGIC))
- HGOTO_ERROR(H5E_SOHM, H5E_CANTLOAD, NULL, "bad SOHM table signature");
- p += H5SM_TABLE_SIZEOF_MAGIC;
+ if(HDmemcmp(p, H5SM_TABLE_MAGIC, (size_t)H5SM_SIZEOF_MAGIC))
+ HGOTO_ERROR(H5E_SOHM, H5E_CANTLOAD, NULL, "bad SOHM table signature")
+ p += H5SM_SIZEOF_MAGIC;
/* Don't count the checksum in the table size yet, since it comes after
* all of the index headers
@@ -250,49 +179,68 @@ H5SM_load_table(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for SOHM indexes")
/* Read in the index headers */
- for(x=0; x<table->num_indexes; ++x) {
- if (H5SM_LIST_VERSION != *p++)
- HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "bad shared message list version number")
+ 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")
- table->indexes[x].index_type= *p++; /* type of the index (list or B-tree) */
+ /* Type of the index (list or B-tree) */
+ table->indexes[x].index_type= *p++;
+
+ /* Type of messages in the index */
UINT16DECODE(p, table->indexes[x].mesg_types);
+
+ /* Minimum size of message to share */
UINT32DECODE(p, table->indexes[x].min_mesg_size);
+
+ /* List cutoff; fewer than this number and index becomes a list */
UINT16DECODE(p, table->indexes[x].list_max);
+
+ /* B-tree cutoff; more than this number and index becomes a B-tree */
UINT16DECODE(p, table->indexes[x].btree_min);
+
+ /* Number of messages shared */
UINT16DECODE(p, table->indexes[x].num_messages);
+
+ /* Address of the actual index */
H5F_addr_decode(f, &p, &(table->indexes[x].index_addr));
+
+ /* Address of the index's heap */
H5F_addr_decode(f, &p, &(table->indexes[x].heap_addr));
- }
+ } /* end for */
/* Read in checksum */
UINT32DECODE(p, stored_chksum);
/* Sanity check */
- HDassert((size_t)(p - buf) == table_size);
+ HDassert((size_t)(p - buf) == size);
/* Compute checksum on entire header */
- computed_chksum = H5_checksum_metadata(buf, (table_size - H5SM_SIZEOF_CHECKSUM), 0);
+ computed_chksum = H5_checksum_metadata(buf, (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 table");
+ HGOTO_ERROR(H5E_SOHM, H5E_BADVALUE, NULL, "incorrect metadata checksum for shared message table")
+ /* Set return value */
ret_value = table;
done:
- /* Free buffer if allocated */
- if(buf)
- buf = H5FL_BLK_FREE(shared_mesg_cache, buf);
+ /* 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);
FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5SM_load_table */
+} /* end H5SM_table_load() */
-
/*-------------------------------------------------------------------------
- * Function: H5SM_clear_table
+ * Function: H5SM_table_flush
*
- * Purpose: Mark this table as no longer being dirty.
+ * Purpose: Flushes (and destroys) the table of Shared Object Header
+ * Message indexes.
*
* Return: Non-negative on success/Negative on failure
*
@@ -302,32 +250,106 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5SM_clear_table(H5F_t *f, H5SM_master_table_t *table, hbool_t destroy)
+H5SM_table_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5SM_master_table_t *table)
{
+ H5WB_t *wb = NULL; /* Wrapped buffer for table data */
+ uint8_t tbl_buf[H5SM_TBL_BUF_SIZE]; /* Buffer for table */
herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT(H5SM_clear_table)
+ FUNC_ENTER_NOAPI_NOINIT(H5SM_table_flush)
- /*
- * Check arguments.
- */
+ /* check arguments */
+ HDassert(f);
+ HDassert(H5F_addr_defined(addr));
HDassert(table);
- /* Reset the dirty flag. */
- table->cache_info.is_dirty = FALSE;
+ 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")
+
+ /* 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;
+
+ /* 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;
+
+ /* 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);
+
+ /* 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);
+
+ /* 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 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);
+ 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_dest_table(f, table) < 0)
- HGOTO_ERROR(H5E_SOHM, H5E_CANTFREE, FAIL, "unable to delete SOHM master table")
+ 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_clear_table */
+} /* end H5SM_table_flush() */
-
/*-------------------------------------------------------------------------
- * Function: H5SM_dest_table
+ * Function: H5SM_table_dest
*
* Purpose: Frees memory used by the SOHM table.
*
@@ -339,10 +361,11 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5SM_dest_table(H5F_t UNUSED *f, H5SM_master_table_t* table)
+H5SM_table_dest(H5F_t UNUSED *f, H5SM_master_table_t* table)
{
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5SM_dest_table)
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5SM_table_dest)
+ /* Sanity check */
HDassert(table);
HDassert(table->indexes);
@@ -351,13 +374,13 @@ H5SM_dest_table(H5F_t UNUSED *f, H5SM_master_table_t* table)
H5FL_FREE(H5SM_master_table_t, table);
FUNC_LEAVE_NOAPI(SUCCEED)
-} /* end H5SM_dest_table */
+} /* end H5SM_table_dest() */
/*-------------------------------------------------------------------------
- * Function: H5SM_table_size
+ * Function: H5SM_table_clear
*
- * Purpose: Returns the size of the table encoded on disk.
+ * Purpose: Mark this table as no longer being dirty.
*
* Return: Non-negative on success/Negative on failure
*
@@ -367,27 +390,33 @@ H5SM_dest_table(H5F_t UNUSED *f, H5SM_master_table_t* table)
*-------------------------------------------------------------------------
*/
static herr_t
-H5SM_table_size(const H5F_t *f, const H5SM_master_table_t *table, size_t *size_ptr)
+H5SM_table_clear(H5F_t *f, H5SM_master_table_t *table, hbool_t destroy)
{
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5SM_table_size)
+ herr_t ret_value = SUCCEED; /* Return value */
- /* check arguments */
- HDassert(f);
+ FUNC_ENTER_NOAPI_NOINIT(H5SM_table_clear)
+
+ /*
+ * Check arguments.
+ */
HDassert(table);
- HDassert(size_ptr);
- /* Set size value */
- *size_ptr = H5SM_TABLE_SIZE(f) + (table->num_indexes * H5SM_INDEX_HEADER_SIZE(f));
+ /* Reset the dirty flag. */
+ table->cache_info.is_dirty = FALSE;
- FUNC_LEAVE_NOAPI(SUCCEED)
-} /* end H5SM_table_size */
+ if(destroy)
+ if(H5SM_table_dest(f, table) < 0)
+ HGOTO_ERROR(H5E_SOHM, H5E_CANTFREE, FAIL, "unable to delete SOHM master table")
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5SM_table_clear() */
/*-------------------------------------------------------------------------
- * Function: H5SM_flush_list
+ * Function: H5SM_table_size
*
- * Purpose: Flush this list index.
+ * Purpose: Returns the size of the table encoded on disk.
*
* Return: Non-negative on success/Negative on failure
*
@@ -397,81 +426,24 @@ H5SM_table_size(const H5F_t *f, const H5SM_master_table_t *table, size_t *size_p
*-------------------------------------------------------------------------
*/
static herr_t
-H5SM_flush_list(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5SM_list_t *list)
+H5SM_table_size(const H5F_t *f, const H5SM_master_table_t *table, size_t *size_ptr)
{
- uint8_t *buf=NULL; /* Temporary buffer */
- herr_t ret_value = SUCCEED;
-
- FUNC_ENTER_NOAPI_NOINIT(H5SM_flush_list)
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5SM_table_size)
/* check arguments */
HDassert(f);
- HDassert(H5F_addr_defined(addr));
- HDassert(list);
- HDassert(list->header);
-
- if (list->cache_info.is_dirty) {
- uint8_t *p; /* Pointer into raw data buffer */
- size_t size; /* Header size on disk */
- uint32_t computed_chksum; /* Computed metadata checksum value */
- hsize_t x;
- hsize_t mesgs_written;
-
- size = H5SM_LIST_SIZE(f, list->header->num_messages);
-
- /* Allocate temporary buffer */
- if(NULL == (buf = H5FL_BLK_MALLOC(shared_mesg_cache, size)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
-
- /* Encode the list */
- p = buf;
-
- /* Encode magic number */
- HDmemcpy(p, H5SM_LIST_MAGIC, (size_t)H5SM_LIST_SIZEOF_MAGIC);
- p += H5SM_LIST_SIZEOF_MAGIC;
-
- /* 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")
-
- p+=H5SM_SOHM_ENTRY_SIZE(f);
- ++mesgs_written;
- }
- }
-
- 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;
- }
-
- if(destroy)
- if(H5SM_dest_list(f, list) < 0)
- HGOTO_ERROR(H5E_SOHM, H5E_CANTFREE, FAIL, "unable to destroy list")
+ HDassert(table);
+ HDassert(size_ptr);
-done:
- /* Free buffer if allocated */
- if(buf)
- buf = H5FL_BLK_FREE(shared_mesg_cache, buf);
+ /* Set size value */
+ *size_ptr = H5SM_TABLE_SIZE(f) + (table->num_indexes * H5SM_INDEX_HEADER_SIZE(f));
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5SM_flush_list */
+ FUNC_LEAVE_NOAPI(SUCCEED)
+} /* end H5SM_table_size() */
-
/*-------------------------------------------------------------------------
- * Function: H5SM_load_list
+ * Function: H5SM_list_load
*
* Purpose: Loads a list of SOHM messages.
*
@@ -483,20 +455,23 @@ done:
*-------------------------------------------------------------------------
*/
static H5SM_list_t *
-H5SM_load_list(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1, void *udata2)
+H5SM_list_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1, void *udata2)
{
- H5SM_list_t *list; /* The SOHM list being read in */
+ 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 */
- size_t size; /* Size of SOHM list on disk */
- uint8_t *buf = NULL; /* 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 */
- hsize_t x; /* Counter variable for messages in list */
- H5SM_list_t *ret_value=NULL;
-
- FUNC_ENTER_NOAPI_NOINIT(H5SM_load_list)
+ 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)
+ /* Sanity check */
HDassert(header);
/* Allocate space for the SOHM list data structure */
@@ -510,28 +485,33 @@ H5SM_load_list(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1,
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")
+
/* Compute the size of the SOHM list on disk */
size = H5SM_LIST_SIZE(f, header->num_messages);
- /* Allocate temporary buffer */
- if(NULL == (buf = H5FL_BLK_MALLOC(shared_mesg_cache, size)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
+ /* 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")
+
+ /* Get temporary pointer to serialized list index */
p = buf;
/* Check magic number */
- if(HDmemcmp(p, H5SM_LIST_MAGIC, (size_t)H5SM_LIST_SIZEOF_MAGIC))
- HGOTO_ERROR(H5E_SOHM, H5E_CANTLOAD, NULL, "bad SOHM list signature");
- p += H5SM_LIST_SIZEOF_MAGIC;
+ if(HDmemcmp(p, H5SM_LIST_MAGIC, (size_t)H5SM_SIZEOF_MAGIC))
+ HGOTO_ERROR(H5E_SOHM, H5E_CANTLOAD, NULL, "bad SOHM list signature")
+ p += H5SM_SIZEOF_MAGIC;
/* Read messages into the list array */
- for(x = 0; x < header->num_messages; x++)
- {
+ for(x = 0; x < header->num_messages; x++) {
if(H5SM_message_decode(f, p, &(list->messages[x])) < 0)
- HGOTO_ERROR(H5E_SOHM, H5E_CANTLOAD, NULL, "can't decode shared message");
+ HGOTO_ERROR(H5E_SOHM, H5E_CANTLOAD, NULL, "can't decode shared message")
p += H5SM_SOHM_ENTRY_SIZE(f);
} /* end for */
@@ -541,42 +521,38 @@ H5SM_load_list(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED *udata1,
/* Sanity check */
HDassert((size_t)(p - buf) == size);
-
/* Compute checksum on entire header */
computed_chksum = H5_checksum_metadata(buf, (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");
-
+ 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++)
list->messages[x].location = H5SM_NO_LOC;
+ /* Set return value */
ret_value = list;
done:
- /* Free buffer if allocated */
- if(buf)
- buf = H5FL_BLK_FREE(shared_mesg_cache, buf);
-
- if(ret_value == NULL) {
- if(list) {
- if(list->messages)
- H5FL_ARR_FREE(H5SM_sohm_t, list->messages);
- H5FL_FREE(H5SM_list_t, list);
- } /* end if */
+ /* 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);
+ H5FL_FREE(H5SM_list_t, list);
} /* end if */
FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5SM_load_list */
+} /* end H5SM_list_load() */
/*-------------------------------------------------------------------------
- * Function: H5SM_clear_list
+ * Function: H5SM_list_flush
*
- * Purpose: Marks a list as not dirty.
+ * Purpose: Flush this list index.
*
* Return: Non-negative on success/Negative on failure
*
@@ -586,31 +562,85 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5SM_clear_list(H5F_t *f, H5SM_list_t *list, hbool_t destroy)
+H5SM_list_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5SM_list_t *list)
{
+ H5WB_t *wb = NULL; /* Wrapped buffer for list index data */
+ uint8_t lst_buf[H5SM_LST_BUF_SIZE]; /* Buffer for list index */
herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT(H5SM_clear_list)
+ FUNC_ENTER_NOAPI_NOINIT(H5SM_list_flush)
- /*
- * Check arguments.
- */
+ /* check arguments */
+ HDassert(f);
+ HDassert(H5F_addr_defined(addr));
HDassert(list);
+ HDassert(list->header);
- /* Reset the dirty flag. */
- list->cache_info.is_dirty = FALSE;
+ 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;
+
+ /* 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")
+
+ 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_dest_list(f, list) < 0)
- HGOTO_ERROR(H5E_SOHM, H5E_CANTFREE, FAIL, "unable to destroy SOHM list")
+ 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 of H5SM_clear_list */
+} /* end H5SM_list_flush() */
/*-------------------------------------------------------------------------
- * Function: H5SM_dest_list
+ * Function: H5SM_list_dest
*
* Purpose: Frees all memory used by the list.
*
@@ -622,9 +652,9 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5SM_dest_list(H5F_t UNUSED *f, H5SM_list_t* list)
+H5SM_list_dest(H5F_t UNUSED *f, H5SM_list_t* list)
{
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5SM_dest_list)
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5SM_list_dest)
HDassert(list);
HDassert(list->messages);
@@ -634,7 +664,43 @@ H5SM_dest_list(H5F_t UNUSED *f, H5SM_list_t* list)
H5FL_FREE(H5SM_list_t, list);
FUNC_LEAVE_NOAPI(SUCCEED)
-} /* end H5SM_dest_list */
+} /* end H5SM_list_dest() */
+
+
+/*-------------------------------------------------------------------------
+ * 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)
+
+ /*
+ * Check arguments.
+ */
+ HDassert(list);
+
+ /* Reset the dirty flag. */
+ list->cache_info.is_dirty = FALSE;
+
+ if(destroy)
+ if(H5SM_list_dest(f, list) < 0)
+ HGOTO_ERROR(H5E_SOHM, H5E_CANTFREE, FAIL, "unable to destroy SOHM list")
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end of H5SM_list_clear() */
/*-------------------------------------------------------------------------
@@ -664,7 +730,5 @@ H5SM_list_size(const H5F_t UNUSED *f, const H5SM_list_t *list, size_t *size_ptr)
*size_ptr = H5SM_LIST_SIZE(f, list->header->list_max);
FUNC_LEAVE_NOAPI(SUCCEED)
-} /* end H5SM_list_size */
+} /* end H5SM_list_size() */
-
-