From 996c2f8d3bac0122fc3c7e5f592d296efc36f58a Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Mon, 27 Jul 2009 17:36:04 -0500 Subject: [svn-r17245] Description: Bring r17230:17244 from trunk to revise_chunks branch. Tested on: FreeBSD/32 6.3 (duty) Mac OS X/32 10.5.7 (amazon) --- MANIFEST | 1 + c++/src/H5AbstractDs.cpp | 5 + c++/src/H5AbstractDs.h | 3 + c++/src/H5Attribute.cpp | 14 +- c++/src/H5Attribute.h | 6 +- c++/src/H5DataSet.cpp | 203 +++++++++++++++++++++-- c++/src/H5DataSet.h | 9 +- c++/test/tvlstr.cpp | 369 ++++++++++++++++++++++++----------------- src/H5Dchunk.c | 111 +++++++------ src/H5Dcompact.c | 36 ++++ src/H5Dcontig.c | 33 ++++ src/H5Defl.c | 1 + src/H5Dint.c | 344 +++++++------------------------------- src/H5Dlayout.c | 418 +++++++++++++++++++++++++++++++++++++++++++++++ src/H5Dpkg.h | 14 +- src/Makefile.am | 4 +- src/Makefile.in | 7 +- 17 files changed, 1057 insertions(+), 521 deletions(-) create mode 100644 src/H5Dlayout.c diff --git a/MANIFEST b/MANIFEST index d90c54d..7751dde 100644 --- a/MANIFEST +++ b/MANIFEST @@ -484,6 +484,7 @@ ./src/H5Dfill.c ./src/H5Dint.c ./src/H5Dio.c +./src/H5Dlayout.c ./src/H5Dmpio.c ./src/H5Doh.c ./src/H5Dpkg.h diff --git a/c++/src/H5AbstractDs.cpp b/c++/src/H5AbstractDs.cpp index a61cc88..19eeb33 100644 --- a/c++/src/H5AbstractDs.cpp +++ b/c++/src/H5AbstractDs.cpp @@ -25,6 +25,11 @@ #include "H5CommonFG.h" #include "H5Alltypes.h" +#include // remove when done + + using std::cerr; + using std::endl; + #ifndef H5_NO_NAMESPACE namespace H5 { #endif diff --git a/c++/src/H5AbstractDs.h b/c++/src/H5AbstractDs.h index c98e5e1..1d04d6c 100644 --- a/c++/src/H5AbstractDs.h +++ b/c++/src/H5AbstractDs.h @@ -51,6 +51,9 @@ class H5_DLLCPP AbstractDs { StrType getStrType() const; VarLenType getVarLenType() const; + // Gets the size in memory of this abstract dataset. + virtual size_t getInMemDataSize() const = 0; + // Gets the dataspace of this abstract dataset - pure virtual. virtual DataSpace getSpace() const = 0; diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp index b1ab73e..6de5e63 100644 --- a/c++/src/H5Attribute.cpp +++ b/c++/src/H5Attribute.cpp @@ -198,35 +198,37 @@ void Attribute::read(const DataType& mem_type, H5std_string& strg) const //-------------------------------------------------------------------------- size_t Attribute::getInMemDataSize() const { + char *func = "Attribute::getInMemDataSize"; + // Get the data type of this attribute hid_t mem_type_id = H5Aget_type(id); - if (mem_type_id <= 0) + if( mem_type_id < 0 ) { - throw AttributeIException("Attribute::getInMemDataSize", "H5Aget_type failed"); + throw AttributeIException(func, "H5Aget_type failed"); } // Get the data type's size hid_t native_type = H5Tget_native_type(mem_type_id, H5T_DIR_DEFAULT); if (native_type < 0) { - throw AttributeIException("Attribute::getInMemDataSize", "H5Tget_native_type failed"); + throw AttributeIException(func, "H5Tget_native_type failed"); } size_t type_size = H5Tget_size(native_type); if (type_size == 0) { - throw AttributeIException("Attribute::getInMemDataSize", "H5Tget_size failed"); + throw AttributeIException(func, "H5Tget_size failed"); } // Get number of elements of the attribute hid_t space_id = H5Aget_space(id); if (space_id < 0) { - throw AttributeIException("Attribute::getInMemDataSize", "H5Aget_space failed"); + throw AttributeIException(func, "H5Aget_space failed"); } hssize_t num_elements = H5Sget_simple_extent_npoints(space_id); if (num_elements < 0) { - throw AttributeIException("Attribute::getInMemDataSize", "H5Sget_simple_extent_npoints failed"); + throw AttributeIException(func, "H5Sget_simple_extent_npoints failed"); } // Calculate and return the size of the data diff --git a/c++/src/H5Attribute.h b/c++/src/H5Attribute.h index abece10..284e5bc 100644 --- a/c++/src/H5Attribute.h +++ b/c++/src/H5Attribute.h @@ -38,10 +38,10 @@ class H5_DLLCPP Attribute : public AbstractDs, public IdComponent { virtual DataSpace getSpace() const; // Returns the amount of storage size required for this attribute. - hsize_t getStorageSize() const; + virtual hsize_t getStorageSize() const; // Returns the in memory size of this attribute's data. - size_t getInMemDataSize() const; + virtual size_t getInMemDataSize() const; // Reads data from this attribute. void read( const DataType& mem_type, void *buf ) const; @@ -82,7 +82,7 @@ class H5_DLLCPP Attribute : public AbstractDs, public IdComponent { // sub-types virtual hid_t p_get_type() const; - // Reads variable or fixed len strings + // Reads variable or fixed len strings from this attribute. void p_read_variable_len(const DataType& mem_type, H5std_string& strg) const; void p_read_fixed_len(const DataType& mem_type, H5std_string& strg) const; diff --git a/c++/src/H5DataSet.cpp b/c++/src/H5DataSet.cpp index 494d3ea..cddb5d4 100644 --- a/c++/src/H5DataSet.cpp +++ b/c++/src/H5DataSet.cpp @@ -37,6 +37,7 @@ #include "H5File.h" #include "H5Attribute.h" #include "H5DataSet.h" +#include "H5private.h" // for HDfree #ifndef H5_NO_NAMESPACE namespace H5 { @@ -220,6 +221,53 @@ hsize_t DataSet::getStorageSize() const } //-------------------------------------------------------------------------- +// Function: DataSet::getInMemDataSize +///\brief Gets the size in memory of the dataset's data. +///\return Size of data (in memory) +///\exception H5::DataSetIException +// Programmer Binh-Minh Ribler - Apr 2009 +//-------------------------------------------------------------------------- +size_t DataSet::getInMemDataSize() const +{ + char *func = "DataSet::getInMemDataSize"; + + // Get the data type of this dataset + hid_t mem_type_id = H5Dget_type(id); + if( mem_type_id < 0 ) + { + throw DataSetIException(func, "H5Dget_type failed"); + } + + // Get the data type's size + hid_t native_type = H5Tget_native_type(mem_type_id, H5T_DIR_DEFAULT); + if (native_type < 0) + { + throw DataSetIException(func, "H5Tget_native_type failed"); + } + size_t type_size = H5Tget_size(native_type); + if (type_size == 0) + { + throw DataSetIException(func, "H5Tget_size failed"); + } + + // Get number of elements of the dataset + hid_t space_id = H5Dget_space(id); // first get its data space + if (space_id < 0) + { + throw DataSetIException(func, "H5Dget_space failed"); + } + hssize_t num_elements = H5Sget_simple_extent_npoints(space_id); + if (num_elements < 0) + { + throw DataSetIException(func, "H5Sget_simple_extent_npoints failed"); + } + + // Calculate and return the size of the data + size_t data_size = type_size * num_elements; + return(data_size); +} + +//-------------------------------------------------------------------------- // Function: DataSet::getOffset ///\brief Returns the address of this dataset in the file. ///\return Address of dataset @@ -364,20 +412,45 @@ void DataSet::read( void* buf, const DataType& mem_type, const DataSpace& mem_sp // Function: DataSet::read ///\brief This is an overloaded member function, provided for convenience. /// It takes a reference to a \c std::string for the buffer. +///\param buf - IN: Buffer for read data +///\param mem_type - IN: Memory datatype +///\param mem_space - IN: Memory dataspace +///\param file_space - IN: Dataset's dataspace in the file +///\param xfer_plist - IN: Transfer property list for this I/O operation +///\exception H5::DataSetIException // Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -void DataSet::read( H5std_string& strg, const DataType& mem_type, const DataSpace& mem_space, const DataSpace& file_space, const DSetMemXferPropList& xfer_plist ) const +// Modification +// Jul 2009 +// Follow the change to Attribute::read and use the following +// private functions to read datasets with fixed- and +// variable-length string: +// DataSet::p_read_fixed_len and +// DataSet::p_read_variable_len +//-------------------------------------------------------------------------- +void DataSet::read(H5std_string& strg, const DataType& mem_type, const DataSpace& mem_space, const DataSpace& file_space, const DSetMemXferPropList& xfer_plist) const { - // Allocate C character string for reading - size_t size = mem_type.getSize(); - char* strg_C = new char[size+1]; // temporary C-string for C API + // Check if this dataset has variable-len string or fixed-len string and + // proceed appropriately. + htri_t is_variable_len = H5Tis_variable_str(mem_type.getId()); + if (is_variable_len < 0) + { + throw DataSetIException("DataSet::read", "H5Tis_variable_str failed"); + } - // Use the overloaded member to read - read(strg_C, mem_type, mem_space, file_space, xfer_plist); + // Obtain identifiers for C API + hid_t mem_type_id = mem_type.getId(); + hid_t mem_space_id = mem_space.getId(); + hid_t file_space_id = file_space.getId(); + hid_t xfer_plist_id = xfer_plist.getId(); - // Get the String and clean up - strg = strg_C; - delete []strg_C; + if (!is_variable_len) // only allocate for fixed-len string + { + p_read_fixed_len(mem_type_id, mem_space_id, file_space_id, xfer_plist_id, strg); + } + else + { + p_read_variable_len(mem_type_id, mem_space_id, file_space_id, xfer_plist_id, strg); + } } //-------------------------------------------------------------------------- @@ -416,15 +489,46 @@ void DataSet::write( const void* buf, const DataType& mem_type, const DataSpace& ///\brief This is an overloaded member function, provided for convenience. /// It takes a reference to a \c std::string for the buffer. // Programmer Binh-Minh Ribler - 2000 +// Modification +// Jul 2009 +// Modified to pass the buffer into H5Dwrite properly depending +// whether the dataset has variable- or fixed-length string. //-------------------------------------------------------------------------- void DataSet::write( const H5std_string& strg, const DataType& mem_type, const DataSpace& mem_space, const DataSpace& file_space, const DSetMemXferPropList& xfer_plist ) const { - // Convert string to C-string - const char* strg_C; - strg_C = strg.c_str(); // strg_C refers to the contents of strg as a C-str + // Check if this attribute has variable-len string or fixed-len string and + // proceed appropriately. + htri_t is_variable_len = H5Tis_variable_str(mem_type.getId()); + if (is_variable_len < 0) + { + throw DataSetIException("DataSet::write", "H5Tis_variable_str failed"); + } + + // Obtain identifiers for C API + hid_t mem_type_id = mem_type.getId(); + hid_t mem_space_id = mem_space.getId(); + hid_t file_space_id = file_space.getId(); + hid_t xfer_plist_id = xfer_plist.getId(); + + // Convert string to C-string + const char* strg_C; + strg_C = strg.c_str(); // strg_C refers to the contents of strg as a C-str + herr_t ret_value = 0; - // Use the overloaded member - write(strg_C, mem_type, mem_space, file_space, xfer_plist); + // Pass string in differently depends on variable or fixed length + if (!is_variable_len) + { + ret_value = H5Dwrite( id, mem_type_id, mem_space_id, file_space_id, xfer_plist_id, strg_C ); + } + else + { + // passing string argument by address + ret_value = H5Dwrite( id, mem_type_id, mem_space_id, file_space_id, xfer_plist_id, &strg_C ); + } + if (ret_value < 0) + { + throw DataSetIException("DataSet::write", "H5Dwrite failed"); + } } //-------------------------------------------------------------------------- @@ -586,7 +690,74 @@ hid_t DataSet::getId() const } //-------------------------------------------------------------------------- -// Function: DataSet::p_setId +// Function: DataSet::p_read_fixed_len (private) +// brief Reads a fixed length \a H5std_string from an dataset. +// param mem_type - IN: DataSet datatype (in memory) +// param strg - IN: Buffer for read string +// exception H5::DataSetIException +// Programmer Binh-Minh Ribler - Jul, 2009 +// Modification +// Jul 2009 +// Added in follow to the change in Attribute::read +//-------------------------------------------------------------------------- +void DataSet::p_read_fixed_len(const hid_t mem_type_id, const hid_t mem_space_id, const hid_t file_space_id, const hid_t xfer_plist_id, H5std_string& strg) const +{ + // Only allocate for fixed-len string. + + // Get the size of the dataset's data + size_t attr_size = getInMemDataSize(); + + // If there is data, allocate buffer and read it. + if (attr_size > 0) + { + char *strg_C = NULL; + + strg_C = new char [(size_t)attr_size+1]; + herr_t ret_value = H5Dread(id, mem_type_id, mem_space_id, file_space_id, xfer_plist_id, strg_C); + + if( ret_value < 0 ) + { + delete []strg_C; // de-allocate for fixed-len string + throw DataSetIException("DataSet::read", "H5Dread failed for fixed length string"); + } + + // Get string from the C char* and release resource allocated locally + strg = strg_C; + delete []strg_C; + } +} + +//-------------------------------------------------------------------------- +// Function: DataSet::p_read_variable_len (private) +// brief Reads a variable length \a H5std_string from an dataset. +// param mem_type - IN: DataSet datatype (in memory) +// param strg - IN: Buffer for read string +// exception H5::DataSetIException +// Programmer Binh-Minh Ribler - Jul, 2009 +// Modification +// Jul 2009 +// Added in follow to the change in Attribute::read +//-------------------------------------------------------------------------- +void DataSet::p_read_variable_len(const hid_t mem_type_id, const hid_t mem_space_id, const hid_t file_space_id, const hid_t xfer_plist_id, H5std_string& strg) const +{ + // Prepare and call C API to read dataset. + char *strg_C; + + // Read dataset, no allocation for variable-len string; C library will + herr_t ret_value = H5Dread(id, mem_type_id, mem_space_id, file_space_id, xfer_plist_id, &strg_C); + + if( ret_value < 0 ) + { + throw DataSetIException("DataSet::read", "H5Dread failed for variable length string"); + } + + // Get string from the C char* and release resource allocated by C API + strg = strg_C; + HDfree(strg_C); +} + +//-------------------------------------------------------------------------- +// Function: DataSet::p_setId (private) ///\brief Sets the identifier of this object to a new value. /// ///\exception H5::IdComponentException when the attempt to close the HDF5 diff --git a/c++/src/H5DataSet.h b/c++/src/H5DataSet.h index f26d775..3d9183d 100644 --- a/c++/src/H5DataSet.h +++ b/c++/src/H5DataSet.h @@ -49,7 +49,10 @@ class H5_DLLCPP DataSet : public H5Object, public AbstractDs { void getSpaceStatus(H5D_space_status_t& status) const; // Returns the amount of storage size required for this dataset. - hsize_t getStorageSize() const; + virtual hsize_t getStorageSize() const; + + // Returns the in memory size of this attribute's data. + virtual size_t getInMemDataSize() const; // Returns the number of bytes required to store VL data. hsize_t getVlenBufSize( DataType& type, DataSpace& space ) const; @@ -113,6 +116,10 @@ class H5_DLLCPP DataSet : public H5Object, public AbstractDs { // sub-types virtual hid_t p_get_type() const; + // Reads variable or fixed len strings from this dataset. + void p_read_fixed_len(const hid_t mem_type_id, const hid_t mem_space_id, const hid_t file_space_id, const hid_t xfer_plist_id, H5std_string& strg) const; + void p_read_variable_len(const hid_t mem_type_id, const hid_t mem_space_id, const hid_t file_space_id, const hid_t xfer_plist_id, H5std_string& strg) const; + protected: // Sets the dataset id. virtual void p_setId(const hid_t new_id); diff --git a/c++/test/tvlstr.cpp b/c++/test/tvlstr.cpp index 0abab1b..01033be 100644 --- a/c++/test/tvlstr.cpp +++ b/c++/test/tvlstr.cpp @@ -18,7 +18,6 @@ tvlstr.cpp - HDF5 C++ testing the Variable-Length String functionality EXTERNAL ROUTINES/VARIABLES: - These routines are in the test directory of the C library: ***************************************************************************/ @@ -52,7 +51,7 @@ const H5std_string FILENAME("tvlstr.h5"); const int SPACE1_RANK = 1; const hsize_t SPACE1_DIM1 = 4; -// Utility functions +// Utility functions - not used now, later though. void *test_vlstr_alloc_custom(size_t size, void *info); void test_vlstr_free_custom(void *mem, void *info); @@ -119,9 +118,9 @@ void test_vlstr_free_custom(void *_mem, void *info) } /*------------------------------------------------------------------------- - * Function: test_vlstrings_basic + * Function: test_vlstring_dataset * - * Purpose: Test simple VL string I/O. + * Purpose: Test writing/reading VL strings on datasets. * * Return: None * @@ -130,98 +129,171 @@ void test_vlstr_free_custom(void *_mem, void *info) * *------------------------------------------------------------------------- */ -static void test_vlstrings_basic() +// String for testing datasets +static char *dynstring_ds_write=NULL; +static char stastring_ds_write[1]={'A'}; + +// Info for a string dataset +const H5std_string DSET1_NAME("String_ds"); +const H5std_string DSET1_DATA("String Dataset"); + +static void test_vlstring_dataset() +{ + // Output message about test being performed + SUBTEST("Testing VL String on Datasets"); + + try { + // Open the file + H5File file1(FILENAME, H5F_ACC_TRUNC); + + // Create a datatype to refer to. + StrType vlst(0, H5T_VARIABLE); + + // Open the root group. + Group root = file1.openGroup("/"); + + // Create dataspace for the dataset. + DataSpace ds_space (H5S_SCALAR); + + // Create an dataset in the root group. + DataSet dset1 = root.createDataSet(DSET1_NAME, vlst, ds_space); + + // Write data to the dataset. + dset1.write(DSET1_DATA, vlst); + + // Read and verify the dataset string as a string of chars. + char *string_ds_check; + dset1.read(&string_ds_check, vlst); + if(HDstrcmp(string_ds_check, DSET1_DATA.c_str())!=0) + TestErrPrintf("Line %d: Attribute data different: DSET1_DATA=%s,string_ds_check=%s\n",__LINE__, DSET1_DATA.c_str(), string_ds_check); + + HDfree(string_ds_check); // note: no need for std::string test + + // Read and verify the dataset string as an std::string. + H5std_string read_str; + dset1.read(read_str, vlst); + if (read_str != DSET1_DATA) + TestErrPrintf("Line %d: Attribute data different: DSET1_DATA=%s,read_str=%s\n",__LINE__, DSET1_DATA.c_str(), read_str.c_str()); + + // Close the dataset. + dset1.close(); + + // Test scalar type dataset with 1 value. + dset1 = root.createDataSet("test_scalar_small", vlst, ds_space); + + dynstring_ds_write = (char*)HDcalloc(1, sizeof(char)); + HDmemset(dynstring_ds_write, 'A', 1); + + // Write data to the dataset, then read it back. + dset1.write(&dynstring_ds_write, vlst); + dset1.read(&string_ds_check, vlst); + + // Verify data read. + if(HDstrcmp(string_ds_check,dynstring_ds_write)!=0) + TestErrPrintf("VL string datasets don't match!, dynstring_ds_write=%s, string_ds_check=%s\n",dynstring_ds_write,string_ds_check); + HDfree(string_ds_check); + dset1.close(); + + // Open dataset DSET1_NAME again. + dset1 = root.openDataSet(DSET1_NAME); + + // Close dataset and file + dset1.close(); + file1.close(); + + PASSED(); + } // end try block + + // Catch all exceptions. + catch (Exception E) { + issue_fail_msg("test_vlstring_dataset()", __LINE__, __FILE__, E.getCDetailMsg()); + } +} // test_vlstring_dataset() + +/*------------------------------------------------------------------------- + * Function: test_vlstring_array_dataset + * + * Purpose: Test writing/reading VL string array to/from datasets. + * + * Return: None + * + * Programmer: Binh-Minh Ribler + * July, 2009 + * + *------------------------------------------------------------------------- + */ +const H5std_string DSSTRARR_NAME("StringArray_dset"); +static void test_vlstring_array_dataset() { - const char *wdata[SPACE1_DIM1]= { - "Four score and seven years ago our forefathers brought forth on this continent a new nation,", - "conceived in liberty and dedicated to the proposition that all men are created equal.", - "Now we are engaged in a great civil war,", - "testing whether that nation or any nation so conceived and so dedicated can long endure." + const char *string_ds_array[SPACE1_DIM1]= { + "Line 1", "Line 2", "Line 3", "Line 4" }; // Information to write // Output message about test being performed - SUBTEST("Testing Basic VL String Functionality"); + SUBTEST("Testing VL String Array on Datasets"); - H5File* file1 = NULL; + H5File* file1; try { // Create file. - file1 = new H5File (FILENAME, H5F_ACC_TRUNC); + file1 = new H5File (FILENAME, H5F_ACC_RDWR); - // Create dataspace for datasets. - hsize_t dims1[] = {SPACE1_DIM1}; - DataSpace sid1(SPACE1_RANK, dims1); + // Create dataspace for datasets. + hsize_t dims1[] = {SPACE1_DIM1}; + DataSpace ds_space(SPACE1_RANK, dims1); // Create a datatype to refer to. - StrType tid1(0, H5T_VARIABLE); + StrType vlst(0, H5T_VARIABLE); // Create and write a dataset. - DataSet dataset(file1->createDataSet("Dataset1", tid1, sid1)); - dataset.write(wdata, tid1); + DataSet dataset(file1->createDataSet(DSSTRARR_NAME, vlst, ds_space)); + dataset.write(string_ds_array, vlst); + + // Read and verify the dataset using strings of chars as buffer. + // Note: reading by array of H5std_string doesn't work yet. + char *string_ds_check[SPACE1_DIM1]; + dataset.read(string_ds_check, vlst); + + int ii; + for (ii = 0; ii < SPACE1_DIM1; ii++) + { + if(HDstrcmp(string_ds_check[ii], string_ds_array[ii])!=0) + TestErrPrintf("Line %d: Dataset data different: written=%s,read=%s\n",__LINE__, string_ds_array[ii], string_ds_check[ii]); + + HDfree(string_ds_check[ii]); + } + + // Close objects that are no longer needed. + dataset.close(); + ds_space.close(); + + // + // Test with scalar data space. + // // Create H5S_SCALAR data space. DataSpace scalar_space; // Create and write another dataset. - DataSet dataset2(file1->createDataSet("Dataset2", tid1, scalar_space)); + DataSet dataset2(file1->createDataSet("Dataset2", vlst, scalar_space)); char *wdata2 = (char*)HDcalloc(65534, sizeof(char)); HDmemset(wdata2, 'A', 65533); - dataset2.write(&wdata2, tid1); + dataset2.write(&wdata2, vlst); + + char *rdata2 = (char*)HDcalloc(65534, sizeof(char)); + HDmemset(rdata2, 0, 65533); + dataset2.read(&rdata2, vlst); + if (HDstrcmp(wdata2, rdata2)!=0) + TestErrPrintf("Line %d: Dataset data different: written=%s,read=%s\n",__LINE__, wdata2, rdata2); // Release resources from second dataset operation. scalar_space.close(); dataset2.close(); HDfree(wdata2); - - // Change to the custom memory allocation routines for reading - // VL string. - DSetMemXferPropList xfer; - size_t mem_used = 0; // Memory used during allocation - xfer.setVlenMemManager(test_vlstr_alloc_custom, &mem_used, test_vlstr_free_custom, &mem_used); - - // Make certain the correct amount of memory will be used. - hsize_t vlsize = dataset.getVlenBufSize(tid1, sid1); - - // Count the actual number of bytes used by the strings. - size_t str_used; // String data in memory - hsize_t i; // counting variable - for (i=0,str_used=0; iclose(); PASSED(); @@ -230,11 +302,10 @@ static void test_vlstrings_basic() // Catch all exceptions. catch (Exception E) { - issue_fail_msg("test_vlstrings_basic()", __LINE__, __FILE__, E.getCDetailMsg()); - if (file1 != NULL) // clean up - delete file1; + issue_fail_msg("test_vlstring_array_dataset()", __LINE__, __FILE__, E.getCDetailMsg()); + delete file1; } -} // end test_vlstrings_basic() +} // end test_vlstring_array_dataset() /*------------------------------------------------------------------------- * Function: test_vlstrings_special @@ -267,13 +338,13 @@ static void test_vlstrings_special() DataSpace sid1(SPACE1_RANK, dims1); // Create a datatype to refer to. - StrType tid1(0, H5T_VARIABLE); + StrType vlst(0, H5T_VARIABLE); // Create a dataset. - DataSet dataset(file1.createDataSet("Dataset3", tid1, sid1)); + DataSet dataset(file1.createDataSet("Dataset3", vlst, sid1)); // Read from the dataset before writing data. - dataset.read(rdata, tid1); + dataset.read(rdata, vlst); // Check data read in. hsize_t i; // counting variable @@ -282,8 +353,8 @@ static void test_vlstrings_special() TestErrPrintf("VL doesn't match!, rdata[%d]=%p\n",(int)i,rdata[i]); // Write dataset to disk, then read it back. - dataset.write(wdata, tid1); - dataset.read(rdata, tid1); + dataset.write(wdata, vlst); + dataset.read(rdata, vlst); // Compare data read in. for(i = 0; i < SPACE1_DIM1; i++) { @@ -300,7 +371,7 @@ static void test_vlstrings_special() } // end for // Reclaim the read VL data. - DataSet::vlenReclaim((void *)rdata, tid1, sid1); + DataSet::vlenReclaim((void *)rdata, vlst, sid1); // Close Dataset. dataset.close(); @@ -313,14 +384,14 @@ static void test_vlstrings_special() // dataset. DSetCreatPropList dcpl; char *fill = NULL; // Fill value - dcpl.setFillValue(tid1, &fill); - dataset = file1.createDataSet("Dataset4", tid1, sid1, dcpl); + dcpl.setFillValue(vlst, &fill); + dataset = file1.createDataSet("Dataset4", vlst, sid1, dcpl); // Close dataset creation property list. dcpl.close(); // Read from dataset before writing data. - dataset.read(rdata, tid1); + dataset.read(rdata, vlst); // Check data read in. for (i=0; iopenStrType(VLSTR_TYPE); + vlst = file1->openStrType(VLSTR_TYPE); // Close datatype and file. - vlstr_type.close(); + vlst.close(); file1->close(); // Open file. file1 = new H5File(FILENAME, H5F_ACC_RDWR); // Open the variable-length string datatype just created - vlstr_type = file1->openStrType(VLSTR_TYPE); + vlst = file1->openStrType(VLSTR_TYPE); // Verify character set and padding - cset = vlstr_type.getCset(); + cset = vlst.getCset(); verify_val(cset, H5T_CSET_ASCII, "StrType::getCset", __LINE__, __FILE__); - pad = vlstr_type.getStrpad(); + pad = vlst.getStrpad(); verify_val(pad, H5T_STR_NULLPAD, "StrType::getStrpad", __LINE__, __FILE__); // Close datatype and file - vlstr_type.close(); + vlst.close(); file1->close(); PASSED(); @@ -436,6 +507,7 @@ static void test_vlstring_type() catch (Exception E) { issue_fail_msg("test_vlstring_type()", __LINE__, __FILE__, E.getCDetailMsg()); + delete file1; } } // end test_vlstring_type() @@ -454,7 +526,7 @@ static void test_vlstring_type() static void test_compact_vlstring() { // Output message about test being performed - SUBTEST("Testing VL Strings in compact dataset"); + SUBTEST("Testing VL Strings on Compact Dataset"); try { // Create file @@ -465,22 +537,22 @@ static void test_compact_vlstring() DataSpace sid1(SPACE1_RANK, dims1); // Create a datatype to refer to - StrType tid1(0, H5T_VARIABLE); + StrType vlst(0, H5T_VARIABLE); // Create dataset create property list and set layout DSetCreatPropList plist; plist.setLayout(H5D_COMPACT); // Create a dataset - DataSet dataset(file1.createDataSet("Dataset5", tid1, sid1, plist)); + DataSet dataset(file1.createDataSet("Dataset5", vlst, sid1, plist)); // Write dataset to disk const char *wdata[SPACE1_DIM1] = {"one", "two", "three", "four"}; - dataset.write(wdata, tid1); + dataset.write(wdata, vlst); // Read dataset from disk char *rdata[SPACE1_DIM1]; // Information read in - dataset.read(rdata, tid1); + dataset.read(rdata, vlst); // Compare data read in hsize_t i; @@ -496,11 +568,11 @@ static void test_compact_vlstring() } // end for // Reclaim the read VL data - DataSet::vlenReclaim((void *)rdata, tid1, sid1); + DataSet::vlenReclaim((void *)rdata, vlst, sid1); // Close objects and file dataset.close(); - tid1.close(); + vlst.close(); sid1.close(); plist.close(); file1.close(); @@ -516,9 +588,9 @@ static void test_compact_vlstring() } // test_compact_vlstrings /*------------------------------------------------------------------------- - * Function: test_write_vl_string_attribute + * Function: test_vlstring_attribute * - * Purpose: Test writing VL strings as attributes. + * Purpose: Test writing/reading VL strings on attributes. * * Return: None * @@ -534,17 +606,17 @@ static char *string_att_write=NULL; const H5std_string ATTRSTR_NAME("String_attr"); const H5std_string ATTRSTR_DATA("String Attribute"); -static void test_write_vl_string_attribute() +static void test_vlstring_attribute() { // Output message about test being performed - SUBTEST("Testing writing VL String as attributes"); + SUBTEST("Testing VL String on Attributes"); try { // Open the file H5File file1(FILENAME, H5F_ACC_RDWR); // Create a datatype to refer to. - StrType tid1(0, H5T_VARIABLE); + StrType vlst(0, H5T_VARIABLE); // Open the root group. Group root = file1.openGroup("/"); @@ -553,14 +625,14 @@ static void test_write_vl_string_attribute() DataSpace att_space (H5S_SCALAR); // Create an attribute for the root group. - Attribute gr_attr = root.createAttribute(ATTRSTR_NAME, tid1, att_space); + Attribute gr_attr = root.createAttribute(ATTRSTR_NAME, vlst, att_space); // Write data to the attribute. - gr_attr.write(tid1, ATTRSTR_DATA); + gr_attr.write(vlst, ATTRSTR_DATA); // Read and verify the attribute string as a string of chars. char *string_att_check; - gr_attr.read(tid1, &string_att_check); + gr_attr.read(vlst, &string_att_check); if(HDstrcmp(string_att_check, ATTRSTR_DATA.c_str())!=0) TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,string_att_check=%s\n",__LINE__, ATTRSTR_DATA.c_str(), string_att_check); @@ -568,7 +640,7 @@ static void test_write_vl_string_attribute() // Read and verify the attribute string as an std::string. H5std_string read_str; - gr_attr.read(tid1, read_str); + gr_attr.read(vlst, read_str); if (read_str != ATTRSTR_DATA) TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,read_str=%s\n",__LINE__, ATTRSTR_DATA.c_str(), read_str.c_str()); @@ -576,28 +648,22 @@ static void test_write_vl_string_attribute() gr_attr.close(); // Test creating a "large" sized string attribute - gr_attr = root.createAttribute("test_scalar_large", tid1, att_space); + gr_attr = root.createAttribute("test_scalar_large", vlst, att_space); string_att_write = (char*)HDcalloc(8192, sizeof(char)); HDmemset(string_att_write, 'A', 8191); // Write data to the attribute, then read it back. - gr_attr.write(tid1, &string_att_write); - gr_attr.read(tid1, &string_att_check); + gr_attr.write(vlst, &string_att_write); + gr_attr.read(vlst, &string_att_check); // Verify data read. if(HDstrcmp(string_att_check,string_att_write)!=0) TestErrPrintf("VL string attributes don't match!, string_att_write=%s, string_att_check=%s\n",string_att_write,string_att_check); - HDfree(string_att_check); - gr_attr.close(); - - // Open attribute ATTRSTR_NAME again. - gr_attr = root.openAttribute(ATTRSTR_NAME); - // The attribute string written is freed below, in the - // test_read_vl_string_attribute() test - - // Close attribute and file + // Release resources. + HDfree(string_att_check); + HDfree(string_att_write); gr_attr.close(); file1.close(); @@ -606,9 +672,9 @@ static void test_write_vl_string_attribute() // Catch all exceptions. catch (Exception E) { - issue_fail_msg("test_string_attr()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_vlstring_attribute()", __LINE__, __FILE__, E.getCDetailMsg()); } -} // test_string_attr() +} // test_vlstring_attribute() /*------------------------------------------------------------------------- * Function: test_read_vl_string_attribute @@ -633,7 +699,7 @@ static void test_read_vl_string_attribute() H5File file1(FILENAME, H5F_ACC_RDONLY); // Create a datatype to refer to. - StrType tid1(0, H5T_VARIABLE); + StrType vlst(0, H5T_VARIABLE); // Open the root group and its attribute named ATTRSTR_NAME. Group root = file1.openGroup("/"); @@ -641,7 +707,7 @@ static void test_read_vl_string_attribute() // Test reading "normal" sized string attribute char *string_att_check; - att.read(tid1, &string_att_check); + att.read(vlst, &string_att_check); if(HDstrcmp(string_att_check,ATTRSTR_DATA.c_str())!=0) TestErrPrintf("VL string attributes don't match!, string_att=%s, string_att_check=%s\n",ATTRSTR_DATA.c_str(),string_att_check); HDfree(string_att_check); @@ -649,7 +715,7 @@ static void test_read_vl_string_attribute() // Test reading "large" sized string attribute att = root.openAttribute("test_scalar_large"); - att.read(tid1, &string_att_check); + att.read(vlst, &string_att_check); if(HDstrcmp(string_att_check,string_att_write)!=0) TestErrPrintf("VL string attributes don't match!, string_att_write=%s, string_att_check=%s\n",string_att_write,string_att_check); HDfree(string_att_check); @@ -657,7 +723,7 @@ static void test_read_vl_string_attribute() // Close objects and file. att.close(); - tid1.close(); + vlst.close(); root.close(); file1.close(); @@ -672,7 +738,7 @@ static void test_read_vl_string_attribute() /*------------------------------------------------------------------------- - * Function: test_vl_stringarray_attribute + * Function: test_vlstring_array_attribute * * Purpose: Test writing/reading VL string array to/from attributes. * @@ -685,21 +751,21 @@ static void test_read_vl_string_attribute() */ const H5std_string ATTRSTRARR_NAME("StringArray_attr"); -static void test_vl_stringarray_attribute() +static void test_vlstring_array_attribute() { const char *string_att_array[SPACE1_DIM1]= { "Line 1", "Line 2", "Line 3", "Line 4" }; // Information to write // Output message about test being performed - SUBTEST("Testing writing/reading VL String Array on attribute"); + SUBTEST("Testing VL String Array on Attributes"); try { // Open the file H5File file1(FILENAME, H5F_ACC_RDWR); // Create a datatype to refer to. - StrType tid1(0, H5T_VARIABLE); + StrType vlst(0, H5T_VARIABLE); // Open the root group. Group root = file1.openGroup("/"); @@ -709,15 +775,15 @@ static void test_vl_stringarray_attribute() DataSpace att_space(SPACE1_RANK, dims1); // Create an attribute for the root group. - Attribute gr_attr = root.createAttribute(ATTRSTRARR_NAME, tid1, att_space); + Attribute gr_attr = root.createAttribute(ATTRSTRARR_NAME, vlst, att_space); // Write data to the attribute. - gr_attr.write(tid1, string_att_array); + gr_attr.write(vlst, string_att_array); // Read and verify the attribute string as a string of chars. // Note: reading by array of H5std_string doesn't work yet. char *string_att_check[SPACE1_DIM1]; - gr_attr.read(tid1, &string_att_check); + gr_attr.read(vlst, &string_att_check); int ii; for (ii = 0; ii < SPACE1_DIM1; ii++) @@ -737,9 +803,9 @@ static void test_vl_stringarray_attribute() // Catch all exceptions. catch (Exception E) { - issue_fail_msg("test_string_attr()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_vlstring_array_attribute()", __LINE__, __FILE__, E.getCDetailMsg()); } -} // test_vl_stringarray_attribute() +} // test_vlstring_array_attribute() /* Helper routine for test_vl_rewrite() */ static void write_scalar_dset(H5File& file, DataType& type, DataSpace& space, @@ -885,17 +951,18 @@ void test_vlstrings() // These tests use the same file // Test basic VL string datatype - test_vlstrings_basic(); + test_vlstring_dataset(); test_vlstrings_special(); test_vlstring_type(); test_compact_vlstring(); // Test using VL strings in attributes - test_write_vl_string_attribute(); - test_read_vl_string_attribute(); + test_vlstring_attribute(); + // test_read_vl_string_attribute(); - // Test using VL string array in attributes - test_vl_stringarray_attribute(); + // Test using VL string array in attributes and datasets + test_vlstring_array_attribute(); + test_vlstring_array_dataset(); // Test writing VL datasets in files with lots of unlinking test_vl_rewrite(); diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c index f0c720e..fdca994 100644 --- a/src/H5Dchunk.c +++ b/src/H5Dchunk.c @@ -181,6 +181,7 @@ static herr_t H5D_chunk_read(H5D_io_info_t *io_info, const H5D_type_info_t *type static herr_t H5D_chunk_write(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 *fm); +static herr_t H5D_chunk_flush(H5D_t *dset, hid_t dxpl_id, unsigned flags); static herr_t H5D_chunk_io_term(const H5D_chunk_map_t *fm); /* "Nonexistent" layout operation callback */ @@ -206,7 +207,10 @@ static herr_t H5D_chunk_file_cb(void *elem, hid_t type_id, unsigned ndims, const hsize_t *coords, void *fm); static herr_t H5D_chunk_mem_cb(void *elem, hid_t type_id, unsigned ndims, const hsize_t *coords, void *fm); - +static herr_t H5D_chunk_flush_entry(const H5D_t *dset, hid_t dxpl_id, + const H5D_dxpl_cache_t *dxpl_cache, H5D_rdcc_ent_t *ent, hbool_t reset); +static herr_t H5D_chunk_cache_evict(const H5D_t *dset, hid_t dxpl_id, + const H5D_dxpl_cache_t *dxpl_cache, H5D_rdcc_ent_t *ent, hbool_t flush); /*********************/ @@ -227,6 +231,7 @@ const H5D_layout_ops_t H5D_LOPS_CHUNK[1] = {{ #endif /* H5_HAVE_PARALLEL */ NULL, NULL, + H5D_chunk_flush, H5D_chunk_io_term }}; @@ -249,6 +254,7 @@ const H5D_layout_ops_t H5D_LOPS_NONEXISTENT[1] = {{ #endif /* H5_HAVE_PARALLEL */ H5D_nonexistent_readvv, NULL, + NULL, NULL }}; @@ -1939,6 +1945,61 @@ done: /*------------------------------------------------------------------------- + * Function: H5D_chunk_flush + * + * Purpose: Writes all dirty chunks to disk and optionally preempts them + * from the cache. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Robb Matzke + * Thursday, May 21, 1998 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5D_chunk_flush(H5D_t *dset, hid_t dxpl_id, unsigned flags) +{ + H5D_dxpl_cache_t _dxpl_cache; /* Data transfer property cache buffer */ + H5D_dxpl_cache_t *dxpl_cache = &_dxpl_cache; /* Data transfer property cache */ + H5D_rdcc_t *rdcc = &(dset->shared->cache.chunk); + unsigned nerrors = 0; + H5D_rdcc_ent_t *ent, *next; + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT(H5D_chunk_flush) + + /* Sanity check */ + HDassert(dset); + + /* Flush any data caught in sieve buffer */ + if(H5D_flush_sieve_buf(dset, dxpl_id) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTFLUSH, FAIL, "unable to flush sieve buffer") + + /* 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") + + /* Loop over all entries in the chunk cache */ + for(ent = rdcc->head; ent; ent = next) { + next = ent->next; + if((flags & H5F_FLUSH_INVALIDATE)) { + if(H5D_chunk_cache_evict(dset, dxpl_id, dxpl_cache, ent, TRUE) < 0) + nerrors++; + } else { + if(H5D_chunk_flush_entry(dset, dxpl_id, dxpl_cache, ent, FALSE) < 0) + nerrors++; + } + } /* end for */ + if(nerrors) + HGOTO_ERROR(H5E_IO, H5E_CANTFLUSH, FAIL, "unable to flush one or more raw data chunks") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5D_chunk_flush() */ + + +/*------------------------------------------------------------------------- * Function: H5D_chunk_io_term * * Purpose: Destroy I/O operation information. @@ -2992,54 +3053,6 @@ done: /*------------------------------------------------------------------------- - * Function: H5D_chunk_flush - * - * Purpose: Writes all dirty chunks to disk and optionally preempts them - * from the cache. - * - * Return: Non-negative on success/Negative on failure - * - * Programmer: Robb Matzke - * Thursday, May 21, 1998 - * - *------------------------------------------------------------------------- - */ -herr_t -H5D_chunk_flush(H5D_t *dset, hid_t dxpl_id, unsigned flags) -{ - H5D_dxpl_cache_t _dxpl_cache; /* Data transfer property cache buffer */ - H5D_dxpl_cache_t *dxpl_cache = &_dxpl_cache; /* Data transfer property cache */ - H5D_rdcc_t *rdcc = &(dset->shared->cache.chunk); - unsigned nerrors = 0; - H5D_rdcc_ent_t *ent, *next; - herr_t ret_value = SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI(H5D_chunk_flush, FAIL) - - /* 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") - - /* Loop over all entries in the chunk cache */ - for(ent = rdcc->head; ent; ent = next) { - next = ent->next; - if((flags & H5F_FLUSH_INVALIDATE)) { - if(H5D_chunk_cache_evict(dset, dxpl_id, dxpl_cache, ent, TRUE) < 0) - nerrors++; - } else { - if(H5D_chunk_flush_entry(dset, dxpl_id, dxpl_cache, ent, FALSE) < 0) - nerrors++; - } - } /* end for */ - if(nerrors) - HGOTO_ERROR(H5E_IO, H5E_CANTFLUSH, FAIL, "unable to flush one or more raw data chunks") - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5D_chunk_flush() */ - - -/*------------------------------------------------------------------------- * Function: H5D_chunk_allocated_cb * * Purpose: Simply counts the number of chunks for a dataset. diff --git a/src/H5Dcompact.c b/src/H5Dcompact.c index 09abee0..a1f5044 100644 --- a/src/H5Dcompact.c +++ b/src/H5Dcompact.c @@ -68,6 +68,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, unsigned flags); /*********************/ @@ -88,6 +89,7 @@ const H5D_layout_ops_t H5D_LOPS_COMPACT[1] = {{ #endif /* H5_HAVE_PARALLEL */ H5D_compact_readvv, H5D_compact_writevv, + H5D_compact_flush, NULL }}; @@ -332,6 +334,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, unsigned UNUSED flags) +{ + 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.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.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. diff --git a/src/H5Dcontig.c b/src/H5Dcontig.c index 887f37a..11ba22c 100644 --- a/src/H5Dcontig.c +++ b/src/H5Dcontig.c @@ -66,6 +66,7 @@ static hbool_t H5D_contig_is_space_alloc(const H5O_layout_t *layout); static herr_t H5D_contig_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); +static herr_t H5D_contig_flush(H5D_t *dset, hid_t dxpl_id, unsigned flags); /* Helper routines */ static herr_t H5D_contig_write_one(H5D_io_info_t *io_info, hsize_t offset, @@ -90,6 +91,7 @@ const H5D_layout_ops_t H5D_LOPS_CONTIG[1] = {{ #endif /* H5_HAVE_PARALLEL */ H5D_contig_readvv, H5D_contig_writevv, + H5D_contig_flush, NULL }}; @@ -1173,6 +1175,37 @@ done: /*------------------------------------------------------------------------- + * Function: H5D_contig_flush + * + * Purpose: Writes all dirty data to disk. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Quincey Koziol + * Monday, July 27, 2009 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5D_contig_flush(H5D_t *dset, hid_t dxpl_id, unsigned UNUSED flags) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT(H5D_contig_flush) + + /* Sanity check */ + HDassert(dset); + + /* Flush any data in sieve buffer */ + if(H5D_flush_sieve_buf(dset, dxpl_id) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTFLUSH, FAIL, "unable to flush sieve buffer") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5D_contig_flush() */ + + +/*------------------------------------------------------------------------- * Function: H5D_contig_copy * * Purpose: Copy contiguous storage raw data from SRC file to DST file. diff --git a/src/H5Defl.c b/src/H5Defl.c index cb31630..b9a8345 100644 --- a/src/H5Defl.c +++ b/src/H5Defl.c @@ -86,6 +86,7 @@ const H5D_layout_ops_t H5D_LOPS_EFL[1] = {{ #endif /* H5_HAVE_PARALLEL */ H5D_efl_readvv, H5D_efl_writevv, + NULL, NULL }}; diff --git a/src/H5Dint.c b/src/H5Dint.c index d67d146..34d69fa 100644 --- a/src/H5Dint.c +++ b/src/H5Dint.c @@ -30,7 +30,6 @@ #include "H5Dpkg.h" /* Datasets */ #include "H5Eprivate.h" /* Error handling */ #include "H5FOprivate.h" /* File objects */ -#include "H5HLprivate.h" /* Local heaps */ #include "H5Iprivate.h" /* IDs */ #include "H5Lprivate.h" /* Links */ #include "H5MMprivate.h" /* Memory management */ @@ -64,7 +63,6 @@ static H5D_shared_t *H5D_new(hid_t dcpl_id, hbool_t creating, hbool_t vl_type); static herr_t H5D_init_type(H5F_t *file, const H5D_t *dset, hid_t type_id, const H5T_t *type); static herr_t H5D_init_space(H5F_t *file, const H5D_t *dset, const H5S_t *space); -static herr_t H5D_set_io_ops(H5D_t *dataset); static herr_t H5D_update_oh_info(H5F_t *file, hid_t dxpl_id, H5D_t *dset, hid_t dapl_id); static herr_t H5D_open_oid(H5D_t *dataset, hid_t dapl_id, hid_t dxpl_id); @@ -692,73 +690,6 @@ done: /*------------------------------------------------------------------------- - * Function: H5D_set_io_ops - * - * Purpose: Set the I/O operation function pointers for a dataset - * - * Return: Non-negative on success/Negative on failure - * - * Programmer: Quincey Koziol - * Thursday, March 20, 2008 - * - *------------------------------------------------------------------------- - */ -static herr_t -H5D_set_io_ops(H5D_t *dataset) -{ - herr_t ret_value = SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI_NOINIT(H5D_set_io_ops) - - /* check args */ - HDassert(dataset); - - /* Set the I/O functions for each layout type */ - switch(dataset->shared->layout.type) { - case H5D_CONTIGUOUS: - if(dataset->shared->dcpl_cache.efl.nused > 0) - dataset->shared->layout.ops = H5D_LOPS_EFL; - else - dataset->shared->layout.ops = H5D_LOPS_CONTIG; - break; - - case H5D_CHUNKED: - dataset->shared->layout.ops = H5D_LOPS_CHUNK; - - /* Set the chunk operations */ - switch(dataset->shared->layout.u.chunk.idx_type) { - case H5D_CHUNK_IDX_BTREE: - dataset->shared->layout.u.chunk.ops = H5D_COPS_BTREE; - break; - - case H5D_CHUNK_IDX_EARRAY: - dataset->shared->layout.u.chunk.ops = H5D_COPS_EARRAY; - break; - - case H5D_CHUNK_IDX_FARRAY: - dataset->shared->layout.u.chunk.ops = H5D_COPS_FARRAY; - break; - - default: - HDassert(0 && "Unknown chunk index method!"); - HGOTO_ERROR(H5E_DATASET, H5E_UNSUPPORTED, FAIL, "unknown chunk index method") - } /* end switch */ - break; - - case H5D_COMPACT: - dataset->shared->layout.ops = H5D_LOPS_COMPACT; - break; - - default: - HGOTO_ERROR(H5E_DATASET, H5E_UNSUPPORTED, FAIL, "unknown storage method") - } /* end switch */ /*lint !e788 All appropriate cases are covered */ - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5D_set_io_ops() */ - - -/*------------------------------------------------------------------------- * Function: H5D_update_oh_info * * Purpose: Create and fill object header for dataset @@ -891,86 +822,13 @@ H5D_update_oh_info(H5F_t *file, hid_t dxpl_id, H5D_t *dset, hid_t dapl_id) if(H5S_append(file, dxpl_id, oh, dset->shared->space) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to update dataspace header message") - /* Update the filters message, if this is a chunked dataset */ - if(layout->type == H5D_CHUNKED) { - H5O_pline_t *pline; /* Dataset's I/O pipeline information */ - - pline = &dset->shared->dcpl_cache.pline; - if(pline->nused > 0 && H5O_msg_append_oh(file, dxpl_id, oh, H5O_PLINE_ID, H5O_MSG_FLAG_CONSTANT, 0, pline) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to update filter header message") - } /* end if */ - - /* Initialize the layout information for the new dataset */ - if(dset->shared->layout.ops->init && (dset->shared->layout.ops->init)(file, dxpl_id, dset, dapl_id) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize layout information") + /* Update/create the layout (and I/O pipeline & EFL) messages */ + if(H5D_layout_oh_create(file, dxpl_id, oh, dset, dapl_id) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to update layout/pline/efl header message") /* Indicate that the layout information was initialized */ layout_init = TRUE; - /* - * Allocate storage if space allocate time is early; otherwise delay - * allocation until later. - */ - if(fill_prop->alloc_time == H5D_ALLOC_TIME_EARLY) - if(H5D_alloc_storage(dset, dxpl_id, H5D_ALLOC_CREATE, FALSE) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize storage") - - /* Update external storage message, if it's used */ - if(dset->shared->dcpl_cache.efl.nused > 0) { - H5O_efl_t *efl = &dset->shared->dcpl_cache.efl; /* Dataset's external file list */ - H5HL_t *heap; /* Pointer to local heap for EFL file names */ - size_t heap_size = H5HL_ALIGN(1); - size_t u; - - /* Determine size of heap needed to stored the file names */ - for(u = 0; u < efl->nused; ++u) - heap_size += H5HL_ALIGN(HDstrlen(efl->slot[u].name) + 1); - - /* Create the heap for the EFL file names */ - if(H5HL_create(file, dxpl_id, heap_size, &efl->heap_addr/*out*/) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to create EFL file name heap") - - /* Pin the heap down in memory */ - if(NULL == (heap = H5HL_protect(file, dxpl_id, efl->heap_addr, H5AC_WRITE))) - HGOTO_ERROR(H5E_DATASET, H5E_CANTPROTECT, FAIL, "unable to protect EFL file name heap") - - /* Insert "empty" name first */ - if((size_t)(-1) == H5HL_insert(file, dxpl_id, heap, (size_t)1, "")) { - H5HL_unprotect(file, dxpl_id, heap, efl->heap_addr); - HGOTO_ERROR(H5E_DATASET, H5E_CANTINSERT, FAIL, "unable to insert file name into heap") - } /* end if */ - - for(u = 0; u < efl->nused; ++u) { - size_t offset; /* Offset of file name in heap */ - - /* Insert file name into heap */ - if((size_t)(-1) == (offset = H5HL_insert(file, dxpl_id, heap, - HDstrlen(efl->slot[u].name) + 1, efl->slot[u].name))) { - H5HL_unprotect(file, dxpl_id, heap, efl->heap_addr); - HGOTO_ERROR(H5E_DATASET, H5E_CANTINSERT, FAIL, "unable to insert file name into heap") - } /* end if */ - - /* Store EFL file name offset */ - HDassert(0 == efl->slot[u].name_offset); - efl->slot[u].name_offset = offset; - } /* end for */ - - /* Release the heap */ - if(H5HL_unprotect(file, dxpl_id, heap, efl->heap_addr) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTUNPROTECT, FAIL, "unable to unprotect EFL file name heap") - heap = NULL; - - /* Insert EFL message into dataset object header */ - if(H5O_msg_append_oh(file, dxpl_id, oh, H5O_EFL_ID, H5O_MSG_FLAG_CONSTANT, 0, efl) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to update external file list message") - } /* end if */ - - /* Create layout message */ - /* (Don't make layout message constant unless allocation time is early, since space may not be allocated) */ - /* (Note: this is relying on H5D_alloc_storage not calling H5O_msg_write during dataset creation) */ - if(H5O_msg_append_oh(file, dxpl_id, oh, H5O_LAYOUT_ID, ((fill_prop->alloc_time == H5D_ALLOC_TIME_EARLY && H5D_COMPACT != layout->type) ? H5O_MSG_FLAG_CONSTANT : 0), 0, layout) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to update layout") - #ifdef H5O_ENABLE_BOGUS { H5P_genplist_t *dc_plist; /* Dataset's creation property list */ @@ -1169,7 +1027,7 @@ H5D_create(H5F_t *file, hid_t type_id, const H5S_t *space, hid_t dcpl_id, new_dset->shared->dcpl_cache.fill.alloc_time = H5D_ALLOC_TIME_EARLY; /* Set the dataset's I/O operations */ - if(H5D_set_io_ops(new_dset) < 0) + if(H5D_layout_set_io_ops(new_dset) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, NULL, "unable to initialize I/O operations") /* Create the layout information for the new dataset */ @@ -1177,7 +1035,7 @@ H5D_create(H5F_t *file, hid_t type_id, const H5S_t *space, hid_t dcpl_id, HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, NULL, "unable to construct layout information") /* Update the dataset's object header info. */ - if(H5D_update_oh_info(file, dxpl_id, new_dset, dapl_id) != SUCCEED) + if(H5D_update_oh_info(file, dxpl_id, new_dset, dapl_id) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, NULL, "can't update the metadata cache") /* Indicate that the layout information was initialized */ @@ -1379,105 +1237,9 @@ H5D_open_oid(H5D_t *dataset, hid_t dapl_id, hid_t dxpl_id) if(NULL == (plist = (H5P_genplist_t *)H5I_object(dataset->shared->dcpl_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "can't get dataset creation property list") - /* Get the optional filters message */ - if((msg_exists = H5O_msg_exists(&(dataset->oloc), H5O_PLINE_ID, dxpl_id)) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't check if message exists") - if(msg_exists) { - /* Retrieve the I/O pipeline message */ - if(NULL == H5O_msg_read(&(dataset->oloc), H5O_PLINE_ID, &dataset->shared->dcpl_cache.pline, dxpl_id)) - HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't retrieve message") - - /* Set the I/O pipeline info in the property list */ - if(H5P_set(plist, H5D_CRT_DATA_PIPELINE_NAME, &dataset->shared->dcpl_cache.pline) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "can't set pipeline") - } /* end if */ - - /* - * Get the raw data layout info. It's actually stored in two locations: - * the storage message of the dataset (dataset->storage) and certain - * values are copied to the dataset create plist so the user can query - * them. - */ - if(NULL == H5O_msg_read(&(dataset->oloc), H5O_LAYOUT_ID, &(dataset->shared->layout), dxpl_id)) - HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to read data layout message") - - /* Check for external file list message (which might not exist) */ - if((msg_exists = H5O_msg_exists(&(dataset->oloc), H5O_EFL_ID, dxpl_id)) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't check if message exists") - if(msg_exists) { - /* Retrieve the EFL message */ - if(NULL == H5O_msg_read(&(dataset->oloc), H5O_EFL_ID, &dataset->shared->dcpl_cache.efl, dxpl_id)) - HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't retrieve message") - - /* Set the EFL info in the property list */ - if(H5P_set(plist, H5D_CRT_EXT_FILE_LIST_NAME, &dataset->shared->dcpl_cache.efl) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "can't set external file list") - - /* Set the dataset's I/O operations */ - dataset->shared->layout.ops = H5D_LOPS_EFL; - } /* end if */ - - /* Sanity check that the layout operations are set up */ - HDassert(dataset->shared->layout.ops); - - /* Adjust chunk dimensions to omit datatype size (in last dimension) for creation property */ - if(H5D_CHUNKED == dataset->shared->layout.type) - dataset->shared->layout.u.chunk.ndims--; - /* Copy layout to the DCPL */ - if(H5P_set(plist, H5D_CRT_LAYOUT_NAME, &dataset->shared->layout) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "can't set layout") - /* Adjust chunk dimensions back again (*sigh*) */ - if(H5D_CHUNKED == dataset->shared->layout.type) - dataset->shared->layout.u.chunk.ndims++; - - switch(dataset->shared->layout.type) { - case H5D_CONTIGUOUS: - /* Compute the size of the contiguous storage for versions of the - * layout message less than version 3 because versions 1 & 2 would - * truncate the dimension sizes to 32-bits of information. - QAK 5/26/04 - */ - if(dataset->shared->layout.version < 3) { - hssize_t snelmts; /* Temporary holder for number of elements in dataspace */ - hsize_t nelmts; /* Number of elements in dataspace */ - size_t dt_size; /* Size of datatype */ - hsize_t tmp_size; /* Temporary holder for raw data size */ - - /* Retrieve the number of elements in the dataspace */ - if((snelmts = H5S_GET_EXTENT_NPOINTS(dataset->shared->space)) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "unable to retrieve number of elements in dataspace") - nelmts = (hsize_t)snelmts; - - /* Get the datatype's size */ - if(0 == (dt_size = H5T_GET_SIZE(dataset->shared->type))) - HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "unable to retrieve size of datatype") - - /* Compute the size of the dataset's contiguous storage */ - tmp_size = nelmts * dt_size; - - /* Check for overflow during multiplication */ - if(nelmts != (tmp_size / dt_size)) - HGOTO_ERROR(H5E_DATASET, H5E_OVERFLOW, FAIL, "size of dataset's storage overflowed") - - /* Assign the dataset's contiguous storage size */ - dataset->shared->layout.u.contig.size = tmp_size; - } /* end if */ - - /* Get the sieve buffer size for this dataset */ - dataset->shared->cache.contig.sieve_buf_size = H5F_SIEVE_BUF_SIZE(dataset->oloc.file); - break; - - case H5D_CHUNKED: - /* Initialize the chunk cache for the dataset */ - if(H5D_chunk_init(dataset->oloc.file, dxpl_id, dataset, dapl_id) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "can't initialize chunk cache") - break; - - case H5D_COMPACT: - break; - - default: - HGOTO_ERROR(H5E_DATASET, H5E_UNSUPPORTED, FAIL, "unknown storage method") - } /* end switch */ /*lint !e788 All appropriate cases are covered */ + /* Get the layout/pline/efl message information */ + if(H5D_layout_oh_read(dataset, dxpl_id, dapl_id, plist) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get layout/pline/efl info") /* Point at dataset's copy, to cache it for later */ fill_prop = &dataset->shared->dcpl_cache.fill; @@ -1868,9 +1630,6 @@ H5D_alloc_storage(H5D_t *dset/*in,out*/, hid_t dxpl_id, H5D_time_alloc_t time_al HDmemset(layout->u.compact.buf, 0, layout->u.compact.size); layout->u.compact.dirty = TRUE; - /* Indicate that we set the storage addr */ - addr_set = TRUE; - /* Indicate that we should initialize storage space */ must_init_space = TRUE; } /* end if */ @@ -2425,6 +2184,47 @@ done: /*------------------------------------------------------------------------- + * Function: H5D_flush_sieve_buf + * + * Purpose: Flush any dataset sieve buffer info cached in memory + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: Quincey Koziol + * July 27, 2009 + * + *------------------------------------------------------------------------- + */ +herr_t +H5D_flush_sieve_buf(H5D_t *dataset, hid_t dxpl_id) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT(H5D_flush_sieve_buf) + + /* Check args */ + HDassert(dataset); + + /* Flush the raw data buffer, if we have a dirty one */ + if(dataset->shared->cache.contig.sieve_buf && dataset->shared->cache.contig.sieve_dirty) { + HDassert(dataset->shared->layout.type != H5D_COMPACT); /* We should never have a sieve buffer for compact storage */ + + /* Write dirty data sieve buffer to file */ + if(H5F_block_write(dataset->oloc.file, H5FD_MEM_DRAW, dataset->shared->cache.contig.sieve_loc, + dataset->shared->cache.contig.sieve_size, dxpl_id, dataset->shared->cache.contig.sieve_buf) < 0) + HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "block write failed") + + /* Reset sieve buffer dirty flag */ + dataset->shared->cache.contig.sieve_dirty = FALSE; + } /* end if */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5D_flush_sieve_buf() */ + + +/*------------------------------------------------------------------------- * Function: H5D_flush_real * * Purpose: Flush any dataset information cached in memory @@ -2458,8 +2258,8 @@ H5D_flush_real(H5D_t *dataset, hid_t dxpl_id, unsigned flags) /* Update the layout on disk, if it's been changed */ if(dataset->shared->layout_dirty) { - if(H5O_msg_write_oh(dataset->oloc.file, dxpl_id, oh, H5O_LAYOUT_ID, H5O_MSG_FLAG_CONSTANT, update_flags, &dataset->shared->layout) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "unable to update layout message") + if(H5D_layout_oh_write(dataset, dxpl_id, oh, update_flags) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "unable to update layout/pline/efl info") dataset->shared->layout_dirty = FALSE; /* Reset the "update the modification time" flag, so we only do it once */ @@ -2480,44 +2280,10 @@ H5D_flush_real(H5D_t *dataset, hid_t dxpl_id, unsigned flags) HDassert(update_flags == 0); } /* end if */ - /* Flush the raw data buffer, if we have a dirty one */ - if(dataset->shared->cache.contig.sieve_buf && dataset->shared->cache.contig.sieve_dirty) { - HDassert(dataset->shared->layout.type != H5D_COMPACT); /* We should never have a sieve buffer for compact storage */ - - /* Write dirty data sieve buffer to file */ - if(H5F_block_write(dataset->oloc.file, H5FD_MEM_DRAW, dataset->shared->cache.contig.sieve_loc, - dataset->shared->cache.contig.sieve_size, dxpl_id, dataset->shared->cache.contig.sieve_buf) < 0) - HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "block write failed") - - /* Reset sieve buffer dirty flag */ - dataset->shared->cache.contig.sieve_dirty = FALSE; - } /* end if */ - - /* Flush cached information for each kind of dataset */ - switch(dataset->shared->layout.type) { - case H5D_CONTIGUOUS: - break; - - case H5D_CHUNKED: - /* Flush the raw data cache */ - if(H5D_chunk_flush(dataset, dxpl_id, flags & H5F_FLUSH_INVALIDATE) < 0) - HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "unable to flush raw data cache") - break; - - case H5D_COMPACT: - if(dataset->shared->layout.u.compact.dirty) { - if(H5O_msg_write(&(dataset->oloc), H5O_LAYOUT_ID, 0, H5O_UPDATE_TIME, &(dataset->shared->layout), dxpl_id) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to update layout message") - dataset->shared->layout.u.compact.dirty = FALSE; - } /* end if */ - break; - - default: - HDassert("not implemented yet" && 0); -#ifdef NDEBUG - HGOTO_ERROR(H5E_IO, H5E_UNSUPPORTED, FAIL, "unsupported storage layout") -#endif /* NDEBUG */ - } /* end switch */ /*lint !e788 All appropriate cases are covered */ + /* Flush cached raw data for each kind of dataset layout */ + if(dataset->shared->layout.ops->flush && + (dataset->shared->layout.ops->flush)(dataset, dxpl_id, flags) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTFLUSH, FAIL, "unable to flush raw data") done: /* Release pointer to object header */ diff --git a/src/H5Dlayout.c b/src/H5Dlayout.c new file mode 100644 index 0000000..82201d2 --- /dev/null +++ b/src/H5Dlayout.c @@ -0,0 +1,418 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/****************/ +/* Module Setup */ +/****************/ + +#define H5D_PACKAGE /*suppress error about including H5Dpkg */ + + +/***********/ +/* Headers */ +/***********/ +#include "H5private.h" /* Generic Functions */ +#include "H5Dpkg.h" /* Datasets */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5HLprivate.h" /* Local heaps */ + + +/****************/ +/* Local Macros */ +/****************/ + + +/******************/ +/* Local Typedefs */ +/******************/ + + +/********************/ +/* Local Prototypes */ +/********************/ + + +/*********************/ +/* Package Variables */ +/*********************/ + + +/*****************************/ +/* Library Private Variables */ +/*****************************/ + + +/*******************/ +/* Local Variables */ +/*******************/ + + + +/*------------------------------------------------------------------------- + * Function: H5D_layout_set_io_ops + * + * Purpose: Set the I/O operation function pointers for a dataset, + * according to the dataset's layout + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Quincey Koziol + * Thursday, March 20, 2008 + * + *------------------------------------------------------------------------- + */ +herr_t +H5D_layout_set_io_ops(const H5D_t *dataset) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(H5D_layout_set_io_ops, FAIL) + + /* check args */ + HDassert(dataset); + + /* Set the I/O functions for each layout type */ + switch(dataset->shared->layout.type) { + case H5D_CONTIGUOUS: + if(dataset->shared->dcpl_cache.efl.nused > 0) + dataset->shared->layout.ops = H5D_LOPS_EFL; + else + dataset->shared->layout.ops = H5D_LOPS_CONTIG; + break; + + case H5D_CHUNKED: + dataset->shared->layout.ops = H5D_LOPS_CHUNK; + + /* Set the chunk operations */ + switch(dataset->shared->layout.u.chunk.idx_type) { + case H5D_CHUNK_IDX_BTREE: + dataset->shared->layout.u.chunk.ops = H5D_COPS_BTREE; + break; + + case H5D_CHUNK_IDX_FARRAY: + dataset->shared->layout.u.chunk.ops = H5D_COPS_FARRAY; + break; + + case H5D_CHUNK_IDX_EARRAY: + dataset->shared->layout.u.chunk.ops = H5D_COPS_EARRAY; + break; + + default: + HDassert(0 && "Unknown chunk index method!"); + HGOTO_ERROR(H5E_DATASET, H5E_UNSUPPORTED, FAIL, "unknown chunk index method") + } /* end switch */ + break; + + case H5D_COMPACT: + dataset->shared->layout.ops = H5D_LOPS_COMPACT; + break; + + default: + HGOTO_ERROR(H5E_DATASET, H5E_UNSUPPORTED, FAIL, "unknown storage method") + } /* end switch */ /*lint !e788 All appropriate cases are covered */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5D_layout_set_io_ops() */ + + +/*------------------------------------------------------------------------- + * Function: H5D_layout_oh_create + * + * Purpose: Create layout/pline/efl information for dataset + * + * Return: Success: SUCCEED + * Failure: FAIL + * + * Programmer: Quincey Koziol + * Monday, July 27, 2009 + * + *------------------------------------------------------------------------- + */ +herr_t +H5D_layout_oh_create(H5F_t *file, hid_t dxpl_id, H5O_t *oh, H5D_t *dset, + hid_t dapl_id) +{ + H5O_layout_t *layout; /* Dataset's layout information */ + const H5O_fill_t *fill_prop; /* Pointer to dataset's fill value information */ + hbool_t layout_init = FALSE; /* Flag to indicate that chunk information was initialized */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT(H5D_layout_oh_create) + + /* Sanity checking */ + HDassert(file); + HDassert(oh); + HDassert(dset); + + /* Set some local variables, for convenience */ + layout = &dset->shared->layout; + fill_prop = &dset->shared->dcpl_cache.fill; + + /* Update the filters message, if this is a chunked dataset */ + if(layout->type == H5D_CHUNKED) { + H5O_pline_t *pline; /* Dataset's I/O pipeline information */ + + pline = &dset->shared->dcpl_cache.pline; + if(pline->nused > 0 && H5O_msg_append_oh(file, dxpl_id, oh, H5O_PLINE_ID, H5O_MSG_FLAG_CONSTANT, 0, pline) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to update filter header message") + } /* end if */ + + /* Initialize the layout information for the new dataset */ + if(dset->shared->layout.ops->init && (dset->shared->layout.ops->init)(file, dxpl_id, dset, dapl_id) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize layout information") + + /* Indicate that the layout information was initialized */ + layout_init = TRUE; + + /* + * Allocate storage if space allocate time is early; otherwise delay + * allocation until later. + */ + if(fill_prop->alloc_time == H5D_ALLOC_TIME_EARLY) + if(H5D_alloc_storage(dset, dxpl_id, H5D_ALLOC_CREATE, FALSE) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize storage") + + /* Update external storage message, if it's used */ + if(dset->shared->dcpl_cache.efl.nused > 0) { + H5O_efl_t *efl = &dset->shared->dcpl_cache.efl; /* Dataset's external file list */ + H5HL_t *heap; /* Pointer to local heap for EFL file names */ + size_t heap_size = H5HL_ALIGN(1); + size_t u; + + /* Determine size of heap needed to stored the file names */ + for(u = 0; u < efl->nused; ++u) + heap_size += H5HL_ALIGN(HDstrlen(efl->slot[u].name) + 1); + + /* Create the heap for the EFL file names */ + if(H5HL_create(file, dxpl_id, heap_size, &efl->heap_addr/*out*/) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to create EFL file name heap") + + /* Pin the heap down in memory */ + if(NULL == (heap = H5HL_protect(file, dxpl_id, efl->heap_addr, H5AC_WRITE))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTPROTECT, FAIL, "unable to protect EFL file name heap") + + /* Insert "empty" name first */ + if((size_t)(-1) == H5HL_insert(file, dxpl_id, heap, (size_t)1, "")) { + H5HL_unprotect(file, dxpl_id, heap, efl->heap_addr); + HGOTO_ERROR(H5E_DATASET, H5E_CANTINSERT, FAIL, "unable to insert file name into heap") + } /* end if */ + + for(u = 0; u < efl->nused; ++u) { + size_t offset; /* Offset of file name in heap */ + + /* Insert file name into heap */ + if((size_t)(-1) == (offset = H5HL_insert(file, dxpl_id, heap, + HDstrlen(efl->slot[u].name) + 1, efl->slot[u].name))) { + H5HL_unprotect(file, dxpl_id, heap, efl->heap_addr); + HGOTO_ERROR(H5E_DATASET, H5E_CANTINSERT, FAIL, "unable to insert file name into heap") + } /* end if */ + + /* Store EFL file name offset */ + HDassert(0 == efl->slot[u].name_offset); + efl->slot[u].name_offset = offset; + } /* end for */ + + /* Release the heap */ + if(H5HL_unprotect(file, dxpl_id, heap, efl->heap_addr) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTUNPROTECT, FAIL, "unable to unprotect EFL file name heap") + heap = NULL; + + /* Insert EFL message into dataset object header */ + if(H5O_msg_append_oh(file, dxpl_id, oh, H5O_EFL_ID, H5O_MSG_FLAG_CONSTANT, 0, efl) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to update external file list message") + } /* end if */ + + /* Create layout message */ + /* (Don't make layout message constant unless allocation time is early, since space may not be allocated) */ + /* (Note: this is relying on H5D_alloc_storage not calling H5O_msg_write during dataset creation) */ + if(H5O_msg_append_oh(file, dxpl_id, oh, H5O_LAYOUT_ID, ((fill_prop->alloc_time == H5D_ALLOC_TIME_EARLY && H5D_COMPACT != layout->type) ? H5O_MSG_FLAG_CONSTANT : 0), 0, layout) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to update layout") + +done: + /* Error cleanup */ + if(ret_value < 0) { + if(dset->shared->layout.type == H5D_CHUNKED && layout_init) { + if(H5D_chunk_dest(file, dxpl_id, dset) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CANTRELEASE, FAIL, "unable to destroy chunk cache") + } /* end if */ + } /* end if */ + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5D_layout_oh_create() */ + + +/*------------------------------------------------------------------------- + * Function: H5D_layout_oh_read + * + * Purpose: Read layout/pline/efl information for dataset + * + * Return: Success: SUCCEED + * Failure: FAIL + * + * Programmer: Quincey Koziol + * Monday, July 27, 2009 + * + *------------------------------------------------------------------------- + */ +herr_t +H5D_layout_oh_read(H5D_t *dataset, hid_t dxpl_id, hid_t dapl_id, H5P_genplist_t *plist) +{ + htri_t msg_exists; /* Whether a particular type of message exists */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT(H5D_layout_oh_read) + + /* Sanity checking */ + HDassert(dataset); + HDassert(plist); + + /* Get the optional filters message */ + if((msg_exists = H5O_msg_exists(&(dataset->oloc), H5O_PLINE_ID, dxpl_id)) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't check if message exists") + if(msg_exists) { + /* Retrieve the I/O pipeline message */ + if(NULL == H5O_msg_read(&(dataset->oloc), H5O_PLINE_ID, &dataset->shared->dcpl_cache.pline, dxpl_id)) + HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't retrieve message") + + /* Set the I/O pipeline info in the property list */ + if(H5P_set(plist, H5D_CRT_DATA_PIPELINE_NAME, &dataset->shared->dcpl_cache.pline) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "can't set pipeline") + } /* end if */ + + /* + * Get the raw data layout info. It's actually stored in two locations: + * the storage message of the dataset (dataset->storage) and certain + * values are copied to the dataset create plist so the user can query + * them. + */ + if(NULL == H5O_msg_read(&(dataset->oloc), H5O_LAYOUT_ID, &(dataset->shared->layout), dxpl_id)) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to read data layout message") + + /* Check for external file list message (which might not exist) */ + if((msg_exists = H5O_msg_exists(&(dataset->oloc), H5O_EFL_ID, dxpl_id)) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't check if message exists") + if(msg_exists) { + /* Retrieve the EFL message */ + if(NULL == H5O_msg_read(&(dataset->oloc), H5O_EFL_ID, &dataset->shared->dcpl_cache.efl, dxpl_id)) + HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't retrieve message") + + /* Set the EFL info in the property list */ + if(H5P_set(plist, H5D_CRT_EXT_FILE_LIST_NAME, &dataset->shared->dcpl_cache.efl) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "can't set external file list") + + /* Set the dataset's I/O operations */ + dataset->shared->layout.ops = H5D_LOPS_EFL; + } /* end if */ + + /* Sanity check that the layout operations are set up */ + HDassert(dataset->shared->layout.ops); + + /* Adjust chunk dimensions to omit datatype size (in last dimension) for creation property */ + if(H5D_CHUNKED == dataset->shared->layout.type) + dataset->shared->layout.u.chunk.ndims--; + /* Copy layout to the DCPL */ + if(H5P_set(plist, H5D_CRT_LAYOUT_NAME, &dataset->shared->layout) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "can't set layout") + /* Adjust chunk dimensions back again (*sigh*) */ + if(H5D_CHUNKED == dataset->shared->layout.type) + dataset->shared->layout.u.chunk.ndims++; + + switch(dataset->shared->layout.type) { + case H5D_CONTIGUOUS: + /* Compute the size of the contiguous storage for versions of the + * layout message less than version 3 because versions 1 & 2 would + * truncate the dimension sizes to 32-bits of information. - QAK 5/26/04 + */ + if(dataset->shared->layout.version < 3) { + hssize_t snelmts; /* Temporary holder for number of elements in dataspace */ + hsize_t nelmts; /* Number of elements in dataspace */ + size_t dt_size; /* Size of datatype */ + hsize_t tmp_size; /* Temporary holder for raw data size */ + + /* Retrieve the number of elements in the dataspace */ + if((snelmts = H5S_GET_EXTENT_NPOINTS(dataset->shared->space)) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "unable to retrieve number of elements in dataspace") + nelmts = (hsize_t)snelmts; + + /* Get the datatype's size */ + if(0 == (dt_size = H5T_GET_SIZE(dataset->shared->type))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "unable to retrieve size of datatype") + + /* Compute the size of the dataset's contiguous storage */ + tmp_size = nelmts * dt_size; + + /* Check for overflow during multiplication */ + if(nelmts != (tmp_size / dt_size)) + HGOTO_ERROR(H5E_DATASET, H5E_OVERFLOW, FAIL, "size of dataset's storage overflowed") + + /* Assign the dataset's contiguous storage size */ + dataset->shared->layout.u.contig.size = tmp_size; + } /* end if */ + + /* Get the sieve buffer size for this dataset */ + dataset->shared->cache.contig.sieve_buf_size = H5F_SIEVE_BUF_SIZE(dataset->oloc.file); + break; + + case H5D_CHUNKED: + /* Initialize the chunk cache for the dataset */ + if(H5D_chunk_init(dataset->oloc.file, dxpl_id, dataset, dapl_id) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "can't initialize chunk cache") + break; + + case H5D_COMPACT: + break; + + default: + HGOTO_ERROR(H5E_DATASET, H5E_UNSUPPORTED, FAIL, "unknown storage method") + } /* end switch */ /*lint !e788 All appropriate cases are covered */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5D_layout_oh_read() */ + + +/*------------------------------------------------------------------------- + * Function: H5D_layout_oh_write + * + * Purpose: Read layout/pline/efl information for dataset + * + * Return: Success: SUCCEED + * Failure: FAIL + * + * Programmer: Quincey Koziol + * Monday, July 27, 2009 + * + *------------------------------------------------------------------------- + */ +herr_t +H5D_layout_oh_write(H5D_t *dataset, hid_t dxpl_id, H5O_t *oh, unsigned update_flags) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT(H5D_layout_oh_write) + + /* Sanity checking */ + HDassert(dataset); + HDassert(oh); + + /* Write the layout message to the dataset's header */ + if(H5O_msg_write_oh(dataset->oloc.file, dxpl_id, oh, H5O_LAYOUT_ID, H5O_MSG_FLAG_CONSTANT, update_flags, &dataset->shared->layout) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "unable to update layout message") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5D_layout_oh_write() */ + diff --git a/src/H5Dpkg.h b/src/H5Dpkg.h index fb2d642..4931bd8 100644 --- a/src/H5Dpkg.h +++ b/src/H5Dpkg.h @@ -130,6 +130,8 @@ typedef ssize_t (*H5D_layout_readvv_func_t)(const struct H5D_io_info_t *io_info, typedef ssize_t (*H5D_layout_writevv_func_t)(const struct H5D_io_info_t *io_info, size_t dset_max_nseq, size_t *dset_curr_seq, size_t dset_len_arr[], hsize_t dset_offset_arr[], size_t mem_max_nseq, size_t *mem_curr_seq, size_t mem_len_arr[], hsize_t mem_offset_arr[]); +typedef herr_t (*H5D_layout_flush_func_t)(H5D_t *dataset, hid_t dxpl_id, + unsigned flags); typedef herr_t (*H5D_layout_io_term_func_t)(const struct H5D_chunk_map_t *cm); /* Typedef for grouping layout I/O routines */ @@ -146,6 +148,7 @@ typedef struct H5D_layout_ops_t { #endif /* H5_HAVE_PARALLEL */ H5D_layout_readvv_func_t readvv; /* Low-level I/O routine for reading data */ H5D_layout_writevv_func_t writevv; /* Low-level I/O routine for writing data */ + H5D_layout_flush_func_t flush; /* Low-level I/O routine for flushing raw data */ H5D_layout_io_term_func_t io_term; /* I/O shutdown routine */ } H5D_layout_ops_t; @@ -564,6 +567,7 @@ H5_DLL herr_t H5D_vlen_get_buf_size(void *elem, hid_t type_id, unsigned ndim, H5_DLL herr_t H5D_check_filters(H5D_t *dataset); H5_DLL herr_t H5D_set_extent(H5D_t *dataset, const hsize_t *size, hid_t dxpl_id); H5_DLL herr_t H5D_get_dxpl_cache(hid_t dxpl_id, H5D_dxpl_cache_t **cache); +H5_DLL herr_t H5D_flush_sieve_buf(H5D_t *dataset, hid_t dxpl_id); /* Functions that perform direct serial I/O operations */ H5_DLL herr_t H5D_select_read(const H5D_io_info_t *io_info, @@ -584,6 +588,15 @@ H5_DLL herr_t H5D_scatgath_write(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); +/* Functions that operate on dataset's layout information */ +H5_DLL herr_t H5D_layout_set_io_ops(const H5D_t *dataset); +H5_DLL herr_t H5D_layout_oh_create(H5F_t *file, hid_t dxpl_id, H5O_t *oh, + H5D_t *dset, hid_t dapl_id); +H5_DLL herr_t H5D_layout_oh_read(H5D_t *dset, hid_t dxpl_id, hid_t dapl_id, + H5P_genplist_t *plist); +H5_DLL herr_t H5D_layout_oh_write(H5D_t *dataset, hid_t dxpl_id, H5O_t *oh, + unsigned update_flags); + /* Functions that operate on contiguous storage */ H5_DLL herr_t H5D_contig_alloc(H5F_t *f, hid_t dxpl_id, H5O_layout_t *layout); H5_DLL herr_t H5D_contig_fill(H5D_t *dset, hid_t dxpl_id); @@ -619,7 +632,6 @@ H5_DLL void *H5D_chunk_lock(const H5D_io_info_t *io_info, H5_DLL herr_t H5D_chunk_unlock(const H5D_io_info_t *io_info, const H5D_chunk_ud_t *udata, hbool_t dirty, unsigned idx_hint, void *chunk, uint32_t naccessed); -H5_DLL herr_t H5D_chunk_flush(H5D_t *dset, hid_t dxpl_id, unsigned flags); H5_DLL herr_t H5D_chunk_flush_entry(const H5D_t *dset, hid_t dxpl_id, const H5D_dxpl_cache_t *dxpl_cache, H5D_rdcc_ent_t *ent, hbool_t reset); H5_DLL herr_t H5D_chunk_allocated(H5D_t *dset, hid_t dxpl_id, hsize_t *nbytes); diff --git a/src/Makefile.am b/src/Makefile.am index e83fba6..ce15dd9 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -48,8 +48,8 @@ libhdf5_la_SOURCES= H5.c H5checksum.c H5dbg.c H5system.c H5timer.c H5trace.c \ H5C.c H5CS.c \ H5D.c H5Dbtree.c H5Dchunk.c H5Dcompact.c H5Dcontig.c H5Ddbg.c \ H5Ddeprec.c H5Dearray.c H5Defl.c H5Dfarray.c H5Dfill.c H5Dint.c \ - H5Dio.c H5Dmpio.c H5Doh.c H5Dproxy.c H5Dscatgath.c H5Dselect.c \ - H5Dtest.c \ + H5Dio.c H5Dlayout.c H5Dmpio.c H5Doh.c H5Dproxy.c H5Dscatgath.c \ + H5Dselect.c H5Dtest.c \ H5E.c H5Edeprec.c H5Eint.c \ H5EA.c H5EAcache.c H5EAdbg.c H5EAdblkpage.c H5EAdblock.c H5EAhdr.c \ H5EAiblock.c H5EAint.c H5EAsblock.c H5EAstat.c H5EAtest.c \ diff --git a/src/Makefile.in b/src/Makefile.in index 07cd6b7..50a9e33 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -85,7 +85,7 @@ am_libhdf5_la_OBJECTS = H5.lo H5checksum.lo H5dbg.lo H5system.lo \ H5B2stat.lo H5B2test.lo H5C.lo H5CS.lo H5D.lo H5Dbtree.lo \ H5Dchunk.lo H5Dcompact.lo H5Dcontig.lo H5Ddbg.lo H5Ddeprec.lo \ H5Dearray.lo H5Defl.lo H5Dfarray.lo H5Dfill.lo H5Dint.lo \ - H5Dio.lo H5Dmpio.lo H5Doh.lo H5Dproxy.lo H5Dscatgath.lo \ + H5Dio.lo H5Dlayout.lo H5Dmpio.lo H5Doh.lo H5Dproxy.lo H5Dscatgath.lo \ H5Dselect.lo H5Dtest.lo H5E.lo H5Edeprec.lo H5Eint.lo H5EA.lo \ H5EAcache.lo H5EAdbg.lo H5EAdblkpage.lo H5EAdblock.lo \ H5EAhdr.lo H5EAiblock.lo H5EAint.lo H5EAsblock.lo H5EAstat.lo \ @@ -434,8 +434,8 @@ libhdf5_la_SOURCES = H5.c H5checksum.c H5dbg.c H5system.c H5timer.c H5trace.c \ H5C.c H5CS.c \ H5D.c H5Dbtree.c H5Dchunk.c H5Dcompact.c H5Dcontig.c H5Ddbg.c \ H5Ddeprec.c H5Dearray.c H5Defl.c H5Dfarray.c H5Dfill.c H5Dint.c \ - H5Dio.c H5Dmpio.c H5Doh.c H5Dproxy.c H5Dscatgath.c H5Dselect.c \ - H5Dtest.c \ + H5Dio.c H5Dlayout.c H5Dmpio.c H5Doh.c H5Dproxy.c H5Dscatgath.c \ + H5Dselect.c H5Dtest.c \ H5E.c H5Edeprec.c H5Eint.c \ H5EA.c H5EAcache.c H5EAdbg.c H5EAdblkpage.c H5EAdblock.c H5EAhdr.c \ H5EAiblock.c H5EAint.c H5EAsblock.c H5EAstat.c H5EAtest.c \ @@ -652,6 +652,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Dfill.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Dint.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Dio.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Dlayout.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Dmpio.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Doh.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Dproxy.Plo@am__quote@ -- cgit v0.12