summaryrefslogtreecommitdiffstats
path: root/src/H5Dcompact.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5Dcompact.c')
-rw-r--r--src/H5Dcompact.c183
1 files changed, 131 insertions, 52 deletions
diff --git a/src/H5Dcompact.c b/src/H5Dcompact.c
index 0458e74..d8bf8b0 100644
--- a/src/H5Dcompact.c
+++ b/src/H5Dcompact.c
@@ -18,7 +18,7 @@
* August 5, 2002
*
* Purpose: Compact dataset I/O functions. These routines are similar
- * H5D_contig_* and H5D_istore_*.
+ * H5D_contig_* and H5D_chunk_*.
*/
/****************/
@@ -38,6 +38,7 @@
#include "H5FDprivate.h" /* File drivers */
#include "H5FLprivate.h" /* Free Lists */
#include "H5Iprivate.h" /* IDs */
+#include "H5MMprivate.h" /* Memory management */
#include "H5Oprivate.h" /* Object headers */
#include "H5Vprivate.h" /* Vector and array functions */
@@ -57,8 +58,8 @@
/********************/
/* Layout operation callbacks */
-static herr_t H5D_compact_new(H5F_t *f, hid_t dxpl_id, H5D_t *dset,
- const H5P_genplist_t *dc_plist);
+static herr_t H5D_compact_construct(H5F_t *f, H5D_t *dset);
+static hbool_t H5D_compact_is_space_alloc(const H5O_storage_t *storage);
static herr_t H5D_compact_io_init(const H5D_io_info_t *io_info, const H5D_type_info_t *type_info,
hsize_t nelmts, const H5S_t *file_space, const H5S_t *mem_space,
H5D_chunk_map_t *cm);
@@ -68,6 +69,7 @@ static ssize_t H5D_compact_readvv(const H5D_io_info_t *io_info,
static ssize_t H5D_compact_writevv(const H5D_io_info_t *io_info,
size_t dset_max_nseq, size_t *dset_curr_seq, size_t dset_size_arr[], hsize_t dset_offset_arr[],
size_t mem_max_nseq, size_t *mem_curr_seq, size_t mem_size_arr[], hsize_t mem_offset_arr[]);
+static herr_t H5D_compact_flush(H5D_t *dset, hid_t dxpl_id);
/*********************/
@@ -76,7 +78,9 @@ static ssize_t H5D_compact_writevv(const H5D_io_info_t *io_info,
/* Compact storage layout I/O ops */
const H5D_layout_ops_t H5D_LOPS_COMPACT[1] = {{
- H5D_compact_new,
+ H5D_compact_construct,
+ NULL,
+ H5D_compact_is_space_alloc,
H5D_compact_io_init,
H5D_contig_read,
H5D_contig_write,
@@ -86,6 +90,7 @@ const H5D_layout_ops_t H5D_LOPS_COMPACT[1] = {{
#endif /* H5_HAVE_PARALLEL */
H5D_compact_readvv,
H5D_compact_writevv,
+ H5D_compact_flush,
NULL
}};
@@ -123,16 +128,16 @@ H5D_compact_fill(H5D_t *dset, hid_t dxpl_id)
/* Check args */
HDassert(TRUE == H5P_isa_class(dxpl_id, H5P_DATASET_XFER));
HDassert(dset && H5D_COMPACT == dset->shared->layout.type);
- HDassert(dset->shared->layout.u.compact.buf);
+ HDassert(dset->shared->layout.storage.u.compact.buf);
HDassert(dset->shared->type);
HDassert(dset->shared->space);
/* Initialize the fill value buffer */
/* (use the compact dataset storage buffer as the fill value buffer) */
- if(H5D_fill_init(&fb_info, dset->shared->layout.u.compact.buf, FALSE,
+ if(H5D_fill_init(&fb_info, dset->shared->layout.storage.u.compact.buf, FALSE,
NULL, NULL, NULL, NULL,
&dset->shared->dcpl_cache.fill, dset->shared->type,
- dset->shared->type_id, (size_t)0, dset->shared->layout.u.compact.size, dxpl_id) < 0)
+ dset->shared->type_id, (size_t)0, dset->shared->layout.storage.u.compact.size, dxpl_id) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "can't initialize fill buffer info")
fb_info_init = TRUE;
@@ -152,7 +157,7 @@ done:
/*-------------------------------------------------------------------------
- * Function: H5D_compact_new
+ * Function: H5D_compact_construct
*
* Purpose: Constructs new compact layout information for dataset
*
@@ -165,37 +170,60 @@ done:
*/
/* ARGSUSED */
static herr_t
-H5D_compact_new(H5F_t *f, hid_t UNUSED dxpl_id, H5D_t *dset,
- const H5P_genplist_t UNUSED *dc_plist)
+H5D_compact_construct(H5F_t *f, H5D_t *dset)
{
hssize_t tmp_size; /* Temporary holder for raw data size */
- hsize_t comp_data_size; /* Size of compact data */
+ hsize_t max_comp_data_size; /* Max. allowed size of compact data */
herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT(H5D_compact_new)
+ FUNC_ENTER_NOAPI_NOINIT(H5D_compact_construct)
/* Sanity checks */
HDassert(f);
HDassert(dset);
- HDassert(dc_plist);
/*
* Compact dataset is stored in dataset object header message of
* layout.
*/
tmp_size = H5S_GET_EXTENT_NPOINTS(dset->shared->space) * H5T_get_size(dset->shared->type);
- H5_ASSIGN_OVERFLOW(dset->shared->layout.u.compact.size, tmp_size, hssize_t, size_t);
+ H5_ASSIGN_OVERFLOW(dset->shared->layout.storage.u.compact.size, tmp_size, hssize_t, size_t);
/* Verify data size is smaller than maximum header message size
* (64KB) minus other layout message fields.
*/
- comp_data_size = H5O_MESG_MAX_SIZE - H5O_layout_meta_size(f, &(dset->shared->layout));
- if(dset->shared->layout.u.compact.size > comp_data_size)
+ max_comp_data_size = H5O_MESG_MAX_SIZE - H5D_layout_meta_size(f, &(dset->shared->layout), FALSE);
+ if(dset->shared->layout.storage.u.compact.size > max_comp_data_size)
HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "compact dataset size is bigger than header message maximum size")
done:
FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5D_compact_new() */
+} /* end H5D_compact_construct() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5D_compact_is_space_alloc
+ *
+ * Purpose: Query if space is allocated for layout
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Quincey Koziol
+ * Thursday, January 15, 2009
+ *
+ *-------------------------------------------------------------------------
+ */
+static hbool_t
+H5D_compact_is_space_alloc(const H5O_storage_t UNUSED *storage)
+{
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5D_compact_is_space_alloc)
+
+ /* Sanity checks */
+ HDassert(storage);
+
+ /* Compact storage is currently always allocated */
+ FUNC_LEAVE_NOAPI(TRUE)
+} /* end H5D_compact_is_space_alloc() */
/*-------------------------------------------------------------------------
@@ -217,8 +245,8 @@ H5D_compact_io_init(const H5D_io_info_t *io_info, const H5D_type_info_t UNUSED *
{
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5D_compact_io_init)
- io_info->store->compact.buf = io_info->dset->shared->layout.u.compact.buf;
- io_info->store->compact.dirty = &io_info->dset->shared->layout.u.compact.dirty;
+ io_info->store->compact.buf = io_info->dset->shared->layout.storage.u.compact.buf;
+ io_info->store->compact.dirty = &io_info->dset->shared->layout.storage.u.compact.dirty;
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5D_compact_io_init() */
@@ -307,6 +335,40 @@ done:
/*-------------------------------------------------------------------------
+ * Function: H5D_compact_flush
+ *
+ * Purpose: Writes dirty compact data to object header
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Quincey Koziol
+ * Monday, July 27, 2009
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5D_compact_flush(H5D_t *dset, hid_t dxpl_id)
+{
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT(H5D_compact_flush)
+
+ /* Sanity check */
+ HDassert(dset);
+
+ /* Check if the buffered compact information is dirty */
+ if(dset->shared->layout.storage.u.compact.dirty) {
+ if(H5O_msg_write(&(dset->oloc), H5O_LAYOUT_ID, 0, H5O_UPDATE_TIME, &(dset->shared->layout), dxpl_id) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to update layout message")
+ dset->shared->layout.storage.u.compact.dirty = FALSE;
+ } /* end if */
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5D_compact_flush() */
+
+
+/*-------------------------------------------------------------------------
* Function: H5D_compact_copy
*
* Purpose: Copy compact storage raw data from SRC file to DST file.
@@ -319,8 +381,9 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5D_compact_copy(H5F_t *f_src, H5O_layout_t *layout_src, H5F_t *f_dst,
- H5O_layout_t *layout_dst, H5T_t *dt_src, H5O_copy_t *cpy_info, hid_t dxpl_id)
+H5D_compact_copy(H5F_t *f_src, H5O_storage_compact_t *storage_src, H5F_t *f_dst,
+ H5O_storage_compact_t *storage_dst, H5T_t *dt_src, H5O_copy_t *cpy_info,
+ hid_t dxpl_id)
{
hid_t tid_src = -1; /* Datatype ID for source datatype */
hid_t tid_dst = -1; /* Datatype ID for destination datatype */
@@ -334,18 +397,22 @@ H5D_compact_copy(H5F_t *f_src, H5O_layout_t *layout_src, H5F_t *f_dst,
FUNC_ENTER_NOAPI(H5D_compact_copy, FAIL)
/* Check args */
- HDassert(layout_src && H5D_COMPACT == layout_src->type);
HDassert(f_src);
+ HDassert(storage_src);
HDassert(f_dst);
- HDassert(layout_dst && H5D_COMPACT == layout_dst->type);
+ HDassert(storage_dst);
HDassert(dt_src);
+ /* Allocate space for destination data */
+ if(NULL == (storage_dst->buf = H5MM_malloc(storage_src->size)))
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "unable to allocate memory for compact dataset")
+
/* Create datatype ID for src datatype, so it gets freed */
- if((tid_src = H5I_register(H5I_DATATYPE, dt_src)) < 0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register source file datatype")
+ if((tid_src = H5I_register(H5I_DATATYPE, dt_src, FALSE)) < 0)
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTREGISTER, FAIL, "unable to register source file datatype")
/* If there's a VLEN source datatype, do type conversion information */
- if(H5T_detect_class(dt_src, H5T_VLEN) > 0) {
+ if(H5T_detect_class(dt_src, H5T_VLEN, FALSE) > 0) {
H5T_path_t *tpath_src_mem, *tpath_mem_dst; /* Datatype conversion paths */
H5T_t *dt_dst; /* Destination datatype */
H5T_t *dt_mem; /* Memory datatype */
@@ -360,22 +427,28 @@ H5D_compact_copy(H5F_t *f_src, H5O_layout_t *layout_src, H5F_t *f_dst,
/* create a memory copy of the variable-length datatype */
if(NULL == (dt_mem = H5T_copy(dt_src, H5T_COPY_TRANSIENT)))
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy")
- if((tid_mem = H5I_register(H5I_DATATYPE, dt_mem)) < 0)
+ if((tid_mem = H5I_register(H5I_DATATYPE, dt_mem, FALSE)) < 0) {
+ H5T_close(dt_mem);
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register memory datatype")
+ } /* end if */
/* create variable-length datatype at the destinaton file */
if(NULL == (dt_dst = H5T_copy(dt_src, H5T_COPY_TRANSIENT)))
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy")
- if(H5T_set_loc(dt_dst, f_dst, H5T_LOC_DISK) < 0)
+ if(H5T_set_loc(dt_dst, f_dst, H5T_LOC_DISK) < 0) {
+ H5T_close(dt_dst);
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "cannot mark datatype on disk")
- if((tid_dst = H5I_register(H5I_DATATYPE, dt_dst)) < 0)
+ } /* end if */
+ if((tid_dst = H5I_register(H5I_DATATYPE, dt_dst, FALSE)) < 0) {
+ H5T_close(dt_dst);
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register destination file datatype")
+ } /* end if */
/* Set up the conversion functions */
if(NULL == (tpath_src_mem = H5T_path_find(dt_src, dt_mem, NULL, NULL, dxpl_id, FALSE)))
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to convert between src and mem datatypes")
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to convert between src and mem datatypes")
if(NULL == (tpath_mem_dst = H5T_path_find(dt_mem, dt_dst, NULL, NULL, dxpl_id, FALSE)))
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to convert between mem and dst datatypes")
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to convert between mem and dst datatypes")
/* Determine largest datatype size */
if(0 == (src_dt_size = H5T_get_size(dt_src)))
@@ -388,7 +461,7 @@ H5D_compact_copy(H5F_t *f_src, H5O_layout_t *layout_src, H5F_t *f_dst,
max_dt_size = MAX(max_dt_size, tmp_dt_size);
/* Set number of whole elements that fit in buffer */
- if(0 == (nelmts = layout_src->u.compact.size / src_dt_size))
+ if(0 == (nelmts = storage_src->size / src_dt_size))
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "element size too large")
/* Set up number of bytes to copy, and initial buffer size */
@@ -402,7 +475,7 @@ H5D_compact_copy(H5F_t *f_src, H5O_layout_t *layout_src, H5F_t *f_dst,
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCREATE, FAIL, "can't create simple dataspace")
/* Atomize */
- if((buf_sid = H5I_register(H5I_DATASPACE, buf_space)) < 0) {
+ if((buf_sid = H5I_register(H5I_DATASPACE, buf_space, FALSE)) < 0) {
H5S_close(buf_space);
HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register dataspace ID")
} /* end if */
@@ -415,23 +488,27 @@ H5D_compact_copy(H5F_t *f_src, H5O_layout_t *layout_src, H5F_t *f_dst,
if(NULL == (buf = H5FL_BLK_MALLOC(type_conv, buf_size)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
- HDmemcpy(buf, layout_src->u.compact.buf, layout_src->u.compact.size);
+ HDmemcpy(buf, storage_src->buf, storage_src->size);
+
+ /* allocate temporary bkg buff for data conversion */
+ if(NULL == (bkg = H5FL_BLK_MALLOC(type_conv, buf_size)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
/* Convert from source file to memory */
- if(H5T_convert(tpath_src_mem, tid_src, tid_mem, nelmts, (size_t)0, (size_t)0, buf, NULL, dxpl_id) < 0)
+ if(H5T_convert(tpath_src_mem, tid_src, tid_mem, nelmts, (size_t)0, (size_t)0, buf, bkg, dxpl_id) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "datatype conversion failed")
+ /* Copy into another buffer, to reclaim memory later */
HDmemcpy(reclaim_buf, buf, buf_size);
- /* allocate temporary bkg buff for data conversion */
- if(NULL == (bkg = H5FL_BLK_CALLOC(type_conv, buf_size)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
+ /* Set background buffer to all zeros */
+ HDmemset(bkg, 0, buf_size);
/* Convert from memory to destination file */
if(H5T_convert(tpath_mem_dst, tid_mem, tid_dst, nelmts, (size_t)0, (size_t)0, buf, bkg, dxpl_id) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "datatype conversion failed")
- HDmemcpy(layout_dst->u.compact.buf, buf, layout_dst->u.compact.size);
+ HDmemcpy(storage_dst->buf, buf, storage_dst->size);
if(H5D_vlen_reclaim(tid_mem, buf_space, H5P_DATASET_XFER_DEFAULT, reclaim_buf) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_BADITER, FAIL, "unable to reclaim variable-length data")
@@ -443,37 +520,39 @@ H5D_compact_copy(H5F_t *f_src, H5O_layout_t *layout_src, H5F_t *f_dst,
size_t ref_count;
/* Determine # of reference elements to copy */
- ref_count = layout_src->u.compact.size / H5T_get_size(dt_src);
+ ref_count = storage_src->size / H5T_get_size(dt_src);
/* Copy objects referenced in source buffer to destination file and set destination elements */
- if(H5O_copy_expand_ref(f_src, layout_src->u.compact.buf, dxpl_id, f_dst,
- layout_dst->u.compact.buf, ref_count, H5T_get_ref_type(dt_src), cpy_info) < 0)
+ if(H5O_copy_expand_ref(f_src, storage_src->buf, dxpl_id, f_dst,
+ storage_dst->buf, ref_count, H5T_get_ref_type(dt_src), cpy_info) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTCOPY, FAIL, "unable to copy reference attribute")
} /* end if */
else
/* Reset value to zero */
- HDmemset(layout_dst->u.compact.buf, 0, layout_src->u.compact.size);
+ HDmemset(storage_dst->buf, 0, storage_src->size);
} /* end if */
else
/* Type conversion not necessary */
- HDmemcpy(layout_dst->u.compact.buf, layout_src->u.compact.buf, layout_src->u.compact.size);
+ HDmemcpy(storage_dst->buf, storage_src->buf, storage_src->size);
} /* end if */
- else
+ else
/* Type conversion not necessary */
- HDmemcpy(layout_dst->u.compact.buf, layout_src->u.compact.buf, layout_src->u.compact.size);
+ HDmemcpy(storage_dst->buf, storage_src->buf, storage_src->size);
+
+ /* Mark destination buffer as dirty */
+ storage_dst->dirty = TRUE;
done:
- if(buf_sid > 0)
- if(H5I_dec_ref(buf_sid) < 0)
- HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't decrement temporary dataspace ID")
+ if(buf_sid > 0 && H5I_dec_ref(buf_sid, FALSE) < 0)
+ HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "can't decrement temporary dataspace ID")
if(tid_src > 0)
- if(H5I_dec_ref(tid_src) < 0)
+ if(H5I_dec_ref(tid_src, FALSE) < 0)
HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't decrement temporary datatype ID")
if(tid_dst > 0)
- if(H5I_dec_ref(tid_dst) < 0)
+ if(H5I_dec_ref(tid_dst, FALSE) < 0)
HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't decrement temporary datatype ID")
if(tid_mem > 0)
- if(H5I_dec_ref(tid_mem) < 0)
+ if(H5I_dec_ref(tid_mem, FALSE) < 0)
HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't decrement temporary datatype ID")
if(buf)
(void)H5FL_BLK_FREE(type_conv, buf);