diff options
author | Raymond Lu <songyulu@hdfgroup.org> | 2012-07-30 22:14:46 (GMT) |
---|---|---|
committer | Raymond Lu <songyulu@hdfgroup.org> | 2012-07-30 22:14:46 (GMT) |
commit | 8a0b4729cdc7b9edb18e84b2b9182228bd6eaa2e (patch) | |
tree | dcc8167037dbe8f34d42b490dfb154a63aa4a687 /src | |
parent | 305950acf96a6f484b5d0a81c083ad138446760f (diff) | |
download | hdf5-8a0b4729cdc7b9edb18e84b2b9182228bd6eaa2e.zip hdf5-8a0b4729cdc7b9edb18e84b2b9182228bd6eaa2e.tar.gz hdf5-8a0b4729cdc7b9edb18e84b2b9182228bd6eaa2e.tar.bz2 |
[svn-r22616] The code for H5PSIdirect_write and its test dectris_tst.c.
Tested on koala and jam.
Diffstat (limited to 'src')
-rw-r--r-- | src/H5Dchunk.c | 100 | ||||
-rw-r--r-- | src/H5Dio.c | 47 | ||||
-rw-r--r-- | src/H5Dprivate.h | 3 | ||||
-rw-r--r-- | src/H5Dpublic.h | 2 | ||||
-rw-r--r-- | src/H5Fprivate.h | 3 | ||||
-rw-r--r-- | src/H5Fquery.c | 29 |
6 files changed, 184 insertions, 0 deletions
diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c index 93e8869..e9a50ef 100644 --- a/src/H5Dchunk.c +++ b/src/H5Dchunk.c @@ -60,6 +60,8 @@ #include "H5Iprivate.h" /* IDs */ #include "H5MMprivate.h" /* Memory management */ #include "H5Vprivate.h" /* Vector and array functions */ +#include "H5Fprivate.h" +#include "H5FDprivate.h" /****************/ @@ -281,6 +283,104 @@ H5FL_DEFINE(H5D_chunk_info_t); /* Declare a free list to manage the chunk sequence information */ H5FL_BLK_DEFINE_STATIC(chunk); + +/*------------------------------------------------------------------------- + * Function: H5D__direct_write + * + * Purpose: Internal routine for H5PSIdirect_write to write a chunk + * directly into the file. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Raymond Lu + * 30 July 2012 + * + *------------------------------------------------------------------------- + */ +herr_t +H5D__direct_write(const H5D_t *dset, hid_t dxpl_id, size_t *offset, size_t buf_size, + const void *buf) +{ + const H5O_layout_t *layout = &(dset->shared->layout); /* Dataset layout */ + H5D_chunk_ud_t udata; /* User data for querying chunk info */ + hsize_t chunk_idx; + H5D_dxpl_cache_t _dxpl_cache; /* Data transfer property cache buffer */ + H5D_dxpl_cache_t *dxpl_cache = &_dxpl_cache; /* Data transfer property cache */ + const H5D_rdcc_t *rdcc = &(dset->shared->cache.chunk); /*raw data chunk cache */ + int space_ndims; /* Dataset's space rank */ + hsize_t space_dim[H5O_LAYOUT_NDIMS]; /* Dataset's dataspace dimensions */ + H5FD_t *lf; + herr_t ret_value = SUCCEED; /* Return value */ + + /*FUNC_ENTER_PACKAGE*/ + FUNC_ENTER_STATIC_TAG(dxpl_id, dset->oloc.addr, FAIL) + + /* Allocate data space and initialize it if it hasn't been. */ + if(!(*dset->shared->layout.ops->is_space_alloc)(&dset->shared->layout.storage)) { + /* Allocate storage */ + if(H5D__alloc_storage(dset, dxpl_id, H5D_ALLOC_WRITE, FALSE, NULL) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize storage") + } /* end if */ + + + /* Retrieve the dataset dimensions */ + if((space_ndims = H5S_get_simple_extent_dims(dset->shared->space, space_dim, NULL)) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to get simple dataspace info") + + /* Calculate the index of this chunk */ + if(H5V_chunk_index((unsigned)space_ndims, offset, + layout->u.chunk.dim, layout->u.chunk.down_chunks, &chunk_idx) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "can't get chunk index") + + /* Find out the file address of the chunk */ + if(H5D__chunk_lookup(dset, dxpl_id, offset, chunk_idx, + &udata) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "error looking up chunk address") + + /* If the chunk hasn't been allocated on disk, do so now. */ + if(!H5F_addr_defined(udata.addr)) { + H5D_chk_idx_info_t idx_info; /* Chunked index info */ + + /* Compose chunked index info struct */ + idx_info.f = dset->oloc.file; + idx_info.dxpl_id = dxpl_id; + idx_info.pline = &(dset->shared->dcpl_cache.pline); + idx_info.layout = &(dset->shared->layout.u.chunk); + idx_info.storage = &(dset->shared->layout.storage.u.chunk); + + /* Set up the size of chunk for user data */ + udata.nbytes = buf_size; + + /* Create the chunk */ + if((dset->shared->layout.storage.u.chunk.ops->insert)(&idx_info, &udata) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINSERT, FAIL, "unable to insert/resize chunk") + + /* Make sure the address of the chunk is returned. */ + if(!H5F_addr_defined(udata.addr)) + HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "chunk address isn't defined") + } /* end if */ + + /* Fill the DXPL cache values for later use */ + if(H5D__get_dxpl_cache(dxpl_id, &dxpl_cache) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't fill dxpl cache") + + /* Evict the entry from the cache if present, but do not flush + * it to disk */ + if(UINT_MAX != udata.idx_hint) { + if(H5D__chunk_cache_evict(dset, dxpl_id, dxpl_cache, + rdcc->slot[udata.idx_hint], FALSE) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTREMOVE, FAIL, "unable to evict chunk") + } /* end if */ + + /* Write the data to the file driver, instead of H5F_block_write */ + lf = H5F_DRIVER(dset->oloc.file); + if(H5FD_write(lf, dxpl_id, H5FD_MEM_DRAW, udata.addr, buf_size, buf) < 0) + HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "file write failed") + +done: + /*FUNC_LEAVE_NOAPI(ret_value)*/ + FUNC_LEAVE_NOAPI_TAG(ret_value, FAIL) +} /*------------------------------------------------------------------------- diff --git a/src/H5Dio.c b/src/H5Dio.c index e34452c..accb948 100644 --- a/src/H5Dio.c +++ b/src/H5Dio.c @@ -271,6 +271,53 @@ done: /*------------------------------------------------------------------------- + * Function: H5PSIdirect_write + * + * Purpose: Temporary name for the DECTRIS project. It writes an entire + * chunk to the file directly. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Raymond Lu + * 30 July 2012 + * + *------------------------------------------------------------------------- + */ +herr_t +H5PSIdirect_write(hid_t dset_id, hid_t dxpl_id, size_t *offset, size_t buf_size, + const void *buf) +{ + H5D_t *dset = NULL; + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API(FAIL) + + /* check arguments */ + if(NULL == (dset = (H5D_t *)H5I_object_verify(dset_id, H5I_DATASET))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset") + if(NULL == dset->oloc.file) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset") + + /* Get the default dataset transfer property list if the user didn't provide one */ + if(H5P_DEFAULT == dxpl_id) + dxpl_id= H5P_DATASET_XFER_DEFAULT; + else + if(TRUE != H5P_isa_class(dxpl_id, H5P_DATASET_XFER)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not xfer parms") + + if(!buf) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no output buffer") + + /* write raw data */ + if(H5D__direct_write(dset, dxpl_id, offset, buf_size, buf) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't write data") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5PSIdirect_write() */ + + +/*------------------------------------------------------------------------- * Function: H5D__read * * Purpose: Reads (part of) a DATASET into application memory BUF. See diff --git a/src/H5Dprivate.h b/src/H5Dprivate.h index 2211f79..b52800b 100644 --- a/src/H5Dprivate.h +++ b/src/H5Dprivate.h @@ -176,5 +176,8 @@ H5_DLL herr_t H5D_chunk_idx_reset(H5O_storage_chunk_t *storage, hbool_t reset_ad H5_DLL herr_t H5D_btree_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE * stream, int indent, int fwidth, unsigned ndims); +H5_DLL herr_t H5D__direct_write(const H5D_t *dset, hid_t dxpl_id, size_t *offset, + size_t buf_size, const void *buf); + #endif /* _H5Dprivate_H */ diff --git a/src/H5Dpublic.h b/src/H5Dpublic.h index c878d4a..b072e64 100644 --- a/src/H5Dpublic.h +++ b/src/H5Dpublic.h @@ -118,6 +118,8 @@ H5_DLL herr_t H5Dread(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t plist_id, void *buf/*out*/); H5_DLL herr_t H5Dwrite(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t plist_id, const void *buf); +H5_DLL herr_t H5PSIdirect_write(hid_t dset_id, hid_t dxpl_id, size_t *offset, size_t buf_size, + const void *buf); H5_DLL herr_t H5Diterate(void *buf, hid_t type_id, hid_t space_id, H5D_operator_t op, void *operator_data); H5_DLL herr_t H5Dvlen_reclaim(hid_t type_id, hid_t space_id, hid_t plist_id, void *buf); diff --git a/src/H5Fprivate.h b/src/H5Fprivate.h index 7c6fae8..3b3af49 100644 --- a/src/H5Fprivate.h +++ b/src/H5Fprivate.h @@ -234,6 +234,7 @@ typedef struct H5F_blk_aggr_t H5F_blk_aggr_t; #define H5F_FILE_ID(F) ((F)->file_id) #define H5F_PARENT(F) ((F)->parent) #define H5F_NMOUNTS(F) ((F)->nmounts) +#define H5F_DRIVER(F) ((F)->shared->lf) #define H5F_DRIVER_ID(F) ((F)->shared->lf->driver_id) #define H5F_GET_FILENO(F,FILENUM) ((FILENUM) = (F)->shared->lf->fileno) #define H5F_HAS_FEATURE(F,FL) ((F)->shared->lf->feature_flags & (FL)) @@ -276,6 +277,7 @@ typedef struct H5F_blk_aggr_t H5F_blk_aggr_t; #define H5F_FILE_ID(F) (H5F_get_file_id(F)) #define H5F_PARENT(F) (H5F_get_parent(F)) #define H5F_NMOUNTS(F) (H5F_get_nmounts(F)) +#define H5F_DRIVER(F) (H5F_get_driver(F)) #define H5F_DRIVER_ID(F) (H5F_get_driver_id(F)) #define H5F_GET_FILENO(F,FILENUM) (H5F_get_fileno((F), &(FILENUM))) #define H5F_HAS_FEATURE(F,FL) (H5F_has_feature(F,FL)) @@ -547,6 +549,7 @@ H5_DLL hbool_t H5F_use_tmp_space(const H5F_t *f); H5_DLL hbool_t H5F_is_tmp_addr(const H5F_t *f, haddr_t addr); /* Functions that retrieve values from VFD layer */ +H5_DLL H5FD_t* H5F_get_driver(const H5F_t *f); H5_DLL hid_t H5F_get_driver_id(const H5F_t *f); H5_DLL herr_t H5F_get_fileno(const H5F_t *f, unsigned long *filenum); H5_DLL hbool_t H5F_has_feature(const H5F_t *f, unsigned feature); diff --git a/src/H5Fquery.c b/src/H5Fquery.c index c04ba24..1be5c50 100644 --- a/src/H5Fquery.c +++ b/src/H5Fquery.c @@ -919,6 +919,35 @@ H5F_get_driver_id(const H5F_t *f) /*------------------------------------------------------------------------- + * Function: H5F_get_driver + * + * Purpose: Quick and dirty routine to retrieve the file's 'driver' structure + * (Mainly added to stop non-file routines from poking about in the + * H5F_t data structure) + * + * Return: 'driver' structure on success/abort on failure (shouldn't fail) + * + * Programmer: Raymond Lu + * 30 July 2012 + * + *------------------------------------------------------------------------- + */ +H5FD_t * +H5F_get_driver(const H5F_t *f) +{ + /* Use FUNC_ENTER_NOAPI_NOINIT_NOERR here to avoid performance issues */ + FUNC_ENTER_NOAPI_NOINIT_NOERR + + HDassert(f); + HDassert(f->shared); + HDassert(f->shared->lf); + + FUNC_LEAVE_NOAPI(f->shared->lf) +} /* end H5F_get_driver() */ + + + +/*------------------------------------------------------------------------- * Function: H5F_get_fileno * * Purpose: Quick and dirty routine to retrieve the file's 'fileno' value |