[svn-r29776] Description:

Bring "file pointer patching" code & test from revise_chunks to trunk.

Tested on:
    MacOSX/64 10.11.4 (amazon) w/serial, parallel & production
    (h5committest forthcoming)
This commit is contained in:
Quincey Koziol 2016-04-24 00:50:00 -05:00
parent 3ac0a74bf3
commit b0980a5f54
7 changed files with 414 additions and 3 deletions

View File

@ -1161,10 +1161,14 @@ H5D__bt2_idx_remove(const H5D_chk_idx_info_t *idx_info, H5D_chunk_common_ud_t *u
HDassert(udata);
/* Check if the v2 B-tree is open yet */
if(NULL == idx_info->storage->u.btree2.bt2)
if(NULL == idx_info->storage->u.btree2.bt2) {
/* Open existing v2 B-tree */
if(H5D__bt2_idx_open(idx_info) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENOBJ, FAIL, "can't open v2 B-tree")
} /* end if */
else /* Patch the top level file pointer contained in bt2 if needed */
if(H5B2_patch_file(idx_info->storage->u.btree2.bt2, idx_info->f) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENOBJ, FAIL, "can't patch v2 B-tree file pointer")
/* Set convenience pointer to v2 B-tree structure */
bt2 = idx_info->storage->u.btree2.bt2;
@ -1479,6 +1483,11 @@ H5D__bt2_idx_dest(const H5D_chk_idx_info_t *idx_info)
/* Check if the v2-btree is open */
if(idx_info->storage->u.btree2.bt2) {
/* Patch the top level file pointer contained in bt2 if needed */
if(H5B2_patch_file(idx_info->storage->u.btree2.bt2, idx_info->f) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENOBJ, FAIL, "can't patch v2 B-tree file pointer")
/* Close v2 B-tree */
if(H5B2_close(idx_info->storage->u.btree2.bt2, idx_info->dxpl_id) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTCLOSEOBJ, FAIL, "can't close v2 B-tree")

View File

@ -1316,10 +1316,13 @@ H5D__earray_idx_remove(const H5D_chk_idx_info_t *idx_info, H5D_chunk_common_ud_t
HDassert(udata);
/* Check if the extensible array is open yet */
if(NULL == idx_info->storage->u.earray.ea)
if(NULL == idx_info->storage->u.earray.ea) {
/* Open the extensible array in file */
if(H5D__earray_idx_open(idx_info) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENOBJ, FAIL, "can't open extensible array")
} else /* Patch the top level file pointer contained in ea if needed */
if(H5EA_patch_file(idx_info->storage->u.earray.ea, idx_info->f) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENOBJ, FAIL, "can't patch earray file pointer")
/* Set convenience pointer to extensible array structure */
ea = idx_info->storage->u.earray.ea;
@ -1729,6 +1732,11 @@ H5D__earray_idx_dest(const H5D_chk_idx_info_t *idx_info)
/* Check if the extensible array is open */
if(idx_info->storage->u.earray.ea) {
/* Patch the top level file pointer contained in ea if needed */
if(H5EA_patch_file(idx_info->storage->u.earray.ea, idx_info->f) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENOBJ, FAIL, "can't patch earray file pointer")
/* Close extensible array */
if(H5EA_close(idx_info->storage->u.earray.ea, idx_info->dxpl_id) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTCLOSEOBJ, FAIL, "unable to close extensible array")

View File

@ -1204,10 +1204,13 @@ H5D__farray_idx_remove(const H5D_chk_idx_info_t *idx_info, H5D_chunk_common_ud_t
HDassert(udata);
/* Check if the fixed array is open yet */
if(NULL == idx_info->storage->u.farray.fa)
if(NULL == idx_info->storage->u.farray.fa) {
/* Open the fixed array in file */
if(H5D__farray_idx_open(idx_info) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENOBJ, FAIL, "can't open fixed array")
} else /* Patch the top level file pointer contained in fa if needed */
if(H5FA_patch_file(idx_info->storage->u.farray.fa, idx_info->f) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENOBJ, FAIL, "can't patch fixed array file pointer")
/* Set convenience pointer to fixed array structure */
fa = idx_info->storage->u.farray.fa;
@ -1626,6 +1629,11 @@ H5D__farray_idx_dest(const H5D_chk_idx_info_t *idx_info)
/* Check if the fixed array is open */
if(idx_info->storage->u.farray.fa) {
/* Patch the top level file pointer contained in fa if needed */
if(H5FA_patch_file(idx_info->storage->u.farray.fa, idx_info->f) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENOBJ, FAIL, "can't patch fixed array file pointer")
/* Close fixed array */
if(H5FA_close(idx_info->storage->u.farray.fa, idx_info->dxpl_id) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTCLOSEOBJ, FAIL, "unable to close fixed array")

View File

@ -939,6 +939,10 @@ H5D__typeinfo_init(const H5D_t *dset, const H5D_dxpl_cache_t *dxpl_cache,
HDassert(type_info);
HDassert(dset);
/* Patch the top level file pointer for dt->shared->u.vlen.f if needed */
if(H5T_patch_vlen_file(dset->shared->type, dset->oloc.file) < 0 )
HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENOBJ, FAIL, "can't patch VL datatype file pointer")
/* Initialize type info safely */
HDmemset(type_info, 0, sizeof(*type_info));

View File

@ -5453,3 +5453,32 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5T_patch_file() */
/*-------------------------------------------------------------------------
* Function: H5T_patch_vlen_file
*
* Purpose: Patch the top-level file pointer contained in (dt->shared->u.vlen.f)
* to point to f. This is possible because
* the top-level file pointer can be closed out from under
* dt while dt is contained in the shared file's cache.
*
* Return: SUCCEED
*
*-------------------------------------------------------------------------
*/
herr_t
H5T_patch_vlen_file(H5T_t *dt, H5F_t *f)
{
FUNC_ENTER_NOAPI_NOINIT_NOERR
/* Sanity check */
HDassert(dt);
HDassert(dt->shared);
HDassert(f);
if((dt->shared->type == H5T_VLEN) && dt->shared->u.vlen.f != f)
dt->shared->u.vlen.f = f;
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5T_patch_vlen_file() */

View File

@ -137,6 +137,7 @@ H5_DLL htri_t H5T_is_sensible(const H5T_t *dt);
H5_DLL uint32_t H5T_hash(H5F_t * file, const H5T_t *dt);
H5_DLL herr_t H5T_set_latest_version(H5T_t *dt);
H5_DLL herr_t H5T_patch_file(H5T_t *dt, H5F_t *f);
H5_DLL herr_t H5T_patch_vlen_file(H5T_t *dt, H5F_t *f);
H5_DLL htri_t H5T_is_variable_str(const H5T_t *dt);
/* Reference specific functions */

View File

@ -2171,6 +2171,356 @@ test_file_double_dataset_open(void)
CHECK(ret, FAIL, "H5Fclose");
} /* end test_file_double_dataset_open() */
/****************************************************************
**
** test_file_double_file_dataset_open():
** This test checks multi-opens of files & datasets:
** It simulates the multi-thread test program from DLS
** which exposes the file pointer segmentation fault failure.
** NOTE: The order on when the files and datasets are open/close
** is important.
**
*****************************************************************/
static void
test_file_double_file_dataset_open(hbool_t new)
{
hid_t fapl = -1; /* File access property list */
hid_t dcpl = -1; /* Dataset creation property list */
hid_t fid1 = -1, fid2 = -1; /* File IDs */
hid_t did1 = -1, did2 = -1; /* Dataset IDs */
hid_t sid1 = -1, sid2 = -1; /* Dataspace IDs */
hid_t tid1 = -1, tid2 = -1; /* Datatype IDs */
hsize_t dims[1] = {5}, dims2[2] = {1, 4}; /* Dimension sizes */
hsize_t e_ext_dims[1] = {7}; /* Expanded dimension sizes */
hsize_t s_ext_dims[1] = {3}; /* Shrunk dimension sizes */
hsize_t max_dims0[1] = {8}; /* Maximum dimension sizes */
hsize_t max_dims1[1] = {H5S_UNLIMITED}; /* Maximum dimesion sizes for extensible array index */
hsize_t max_dims2[2] = {H5S_UNLIMITED, H5S_UNLIMITED}; /* Maximum dimension sizes for v2 B-tree index */
hsize_t chunks[1] = {2}, chunks2[2] = {4, 5}; /* Chunk dimension sizes */
char* data[] = {"String 1", "String 2", "String 3", "String 4", "String 5"}; /* Input Data */
char* e_data[] = {"String 1", "String 2", "String 3", "String 4", "String 5", "String 6", "String 7"}; /* Input Data */
char* buffer[5]; /* Output buffer */
int wbuf[4] = {1, 2, 3, 4}; /* Input data */
herr_t ret; /* Generic return value */
/* Output message about test being performed */
MESSAGE(5, ("Testing double file and dataset open/close\n"));
/* Setting up test file */
fapl = H5Pcreate(H5P_FILE_ACCESS);
CHECK(fapl, FAIL, "H5Pcreate");
if(new) {
ret = H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST);
CHECK(ret, FAIL, "H5Pset_libver_bounds");
}
/* Create the test file */
fid1 = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
CHECK(fid1, FAIL, "H5Fcreate");
/* Create a chunked dataset with fixed array indexing */
sid1 = H5Screate_simple(1, dims, max_dims0);
CHECK(sid1, FAIL, "H5Screate");
tid1 = H5Tcopy(H5T_C_S1);
CHECK(tid1, FAIL, "H5Tcopy");
ret = H5Tset_size(tid1, H5T_VARIABLE);
CHECK(ret, FAIL, "H5Tset_size");
dcpl = H5Pcreate(H5P_DATASET_CREATE);
CHECK(dcpl, FAIL, "H5Pcreate");
ret = H5Pset_chunk(dcpl, 1, chunks);
CHECK(ret, FAIL, "H5Pset_chunk");
did1 = H5Dcreate2(fid1, "dset_fa", tid1, sid1, H5P_DEFAULT, dcpl, H5P_DEFAULT);
CHECK(did1, FAIL, "H5Dcreate2");
/* Closing */
ret = H5Dclose(did1);
CHECK(ret, FAIL, "H5Dclose");
ret = H5Tclose(tid1);
CHECK(ret, FAIL, "H5Tclose");
ret = H5Sclose(sid1);
CHECK(ret, FAIL, "H5Sclose");
ret = H5Pclose(dcpl);
CHECK(ret, FAIL, "H5Dclose");
/* Create a chunked dataset with extensible array indexing */
sid1 = H5Screate_simple(1, dims, max_dims1);
CHECK(sid1, FAIL, "H5Screate");
tid1 = H5Tcopy(H5T_C_S1);
CHECK(tid1, FAIL, "H5Tcopy");
ret = H5Tset_size(tid1, H5T_VARIABLE);
CHECK(ret, FAIL, "H5Tset_size");
dcpl = H5Pcreate(H5P_DATASET_CREATE);
CHECK(dcpl, FAIL, "H5Pcreate");
ret = H5Pset_chunk(dcpl, 1, chunks);
CHECK(ret, FAIL, "H5Pset_chunk");
did1 = H5Dcreate2(fid1, "dset_ea", tid1, sid1, H5P_DEFAULT, dcpl, H5P_DEFAULT);
CHECK(did1, FAIL, "H5Dcreate2");
/* Write to the dataset */
ret = H5Dwrite(did1, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
CHECK(ret, FAIL, "H5Dwrite");
/* Closing */
ret = H5Dclose(did1);
CHECK(ret, FAIL, "H5Dclose");
ret = H5Tclose(tid1);
CHECK(ret, FAIL, "H5Tclose");
ret = H5Sclose(sid1);
CHECK(ret, FAIL, "H5Sclose");
ret = H5Pclose(dcpl);
CHECK(ret, FAIL, "H5Dclose");
/* Create a chunked dataset with v2 btree indexing */
sid2 = H5Screate_simple(2, dims2, max_dims2);
CHECK(sid2, FAIL, "H5Screate");
dcpl = H5Pcreate(H5P_DATASET_CREATE);
CHECK(dcpl, FAIL, "H5Pcreate");
ret = H5Pset_chunk(dcpl, 2, chunks2);
CHECK(ret, FAIL, "H5Pset_chunk");
did2 = H5Dcreate2(fid1, "dset_bt2", H5T_NATIVE_INT, sid2, H5P_DEFAULT, dcpl, H5P_DEFAULT);
CHECK(did2, FAIL, "H5Dcreate2");
/* Write to the dataset */
ret = H5Dwrite(did2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf);
CHECK(ret, FAIL, "H5Dwrite");
/* Closing */
ret = H5Dclose(did2);
CHECK(ret, FAIL, "H5Dclose");
ret = H5Sclose(sid2);
CHECK(ret, FAIL, "H5Sclose");
ret = H5Pclose(dcpl);
CHECK(ret, FAIL, "H5Pclose");
ret = H5Pclose(fapl);
CHECK(ret, FAIL, "H5Pclose");
ret = H5Fclose(fid1);
CHECK(ret, FAIL, "H5Fclose");
/*
* Scenario 1
*/
/* First file open */
fid1 = H5Fopen(FILE1, H5F_ACC_RDWR, H5P_DEFAULT);
CHECK(fid1, FAIL, "H5Fopen");
/* First file's dataset open */
did1 = H5Dopen2(fid1, "/dset_fa", H5P_DEFAULT);
CHECK(did1, FAIL, "H5Dopen2");
tid1 = H5Tcopy(did1);
CHECK(tid1, FAIL, "H5Tcopy");
/* First file's dataset write */
ret = H5Dwrite(did1, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
CHECK(ret, FAIL, "H5Dwrite");
/* Second file open */
fid2 = H5Fopen(FILE1, H5F_ACC_RDWR, H5P_DEFAULT);
CHECK(fid2, FAIL, "H5Fopen");
/* Second file's dataset open */
did2 = H5Dopen2(fid2, "/dset_fa", H5P_DEFAULT );
CHECK(did2, FAIL, "H5Dopen2");
tid2 = H5Tcopy(did2);
CHECK(tid2, FAIL, "H5Tcopy");
/* First file's dataset close */
ret = H5Dclose(did1);
CHECK(ret, FAIL, "H5Dclose");
/* First file close */
ret = H5Fclose(fid1);
CHECK(ret, FAIL, "H5Fclose");
/* Second file's dataset write */
ret = H5Dwrite(did2, tid2, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
CHECK(ret, FAIL, "H5Dwrite");
/* Second file's dataset close */
ret = H5Dclose(did2);
CHECK(ret, FAIL, "H5Dclose");
/* Second file close */
ret = H5Fclose(fid2);
CHECK(ret, FAIL, "H5Fclose");
/* Closing */
ret = H5Tclose(tid1);
CHECK(ret, FAIL, "H5Tclose");
ret = H5Tclose(tid2);
CHECK(ret, FAIL, "H5Tclose");
/*
* Scenario 2
*/
/* First file open */
fid1 = H5Fopen(FILE1, H5F_ACC_RDONLY, H5P_DEFAULT);
CHECK(fid1, FAIL, "H5Fopen");
/* Second file open */
fid2 = H5Fopen(FILE1, H5F_ACC_RDONLY, H5P_DEFAULT);
CHECK(fid2, FAIL, "H5Fopen");
/* Second file's dataset open */
did2 = H5Dopen2(fid2, "/dset_ea", H5P_DEFAULT );
CHECK(did2, FAIL, "H5Dopen2");
tid2 = H5Tcopy(did2);
CHECK(tid2, FAIL, "H5Tcopy");
/* First file's dataset open */
did1 = H5Dopen2(fid1, "/dset_ea", H5P_DEFAULT);
CHECK(did1, FAIL, "H5Dopen2");
tid1 = H5Tcopy(did1);
CHECK(tid1, FAIL, "H5Tcopy");
/* Second file's dataset read */
HDmemset(buffer, 0, sizeof(char*) * 5);
ret = H5Dread(did2, tid2, H5S_ALL, H5S_ALL, H5P_DEFAULT, buffer);
CHECK(ret, FAIL, "H5Dread");
/* Second file's dataset close */
ret = H5Dclose(did2);
CHECK(ret, FAIL, "H5Dclose");
/* Second file close */
ret = H5Fclose(fid2);
CHECK(ret, FAIL, "H5Fclose");
/* First file's dataset read */
HDmemset(buffer, 0, sizeof(char*) * 5);
ret = H5Dread(did1, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, buffer);
/* First file's dataset close */
ret = H5Dclose(did1);
CHECK(ret, FAIL, "H5Dclose");
/* First file close */
ret = H5Fclose(fid1);
CHECK(ret, FAIL, "H5Fclose");
/* Closing */
ret = H5Tclose(tid1);
CHECK(ret, FAIL, "H5Tclose");
ret = H5Tclose(tid2);
CHECK(ret, FAIL, "H5Tclose");
/*
* Scenario 3
*/
/* First file open */
fid1 = H5Fopen(FILE1, H5F_ACC_RDONLY, H5P_DEFAULT);
CHECK(fid1, FAIL, "H5Fopen");
/* First file's dataset open */
did1 = H5Dopen2(fid1, "/dset_bt2", H5P_DEFAULT);
CHECK(did1, FAIL, "H5Dopen2");
/* First file's get storage size */
ret = H5Dget_storage_size(did1);
CHECK(ret, FAIL, "H5Dget_storage_size");
/* Second file open */
fid2 = H5Fopen(FILE1, H5F_ACC_RDONLY, H5P_DEFAULT);
CHECK(fid2, FAIL, "H5Fopen");
/* Second file's dataset open */
did2 = H5Dopen2(fid2, "/dset_bt2", H5P_DEFAULT );
CHECK(did2, FAIL, "H5Dopen2");
/* First file's dataset close */
ret = H5Dclose(did1);
CHECK(ret, FAIL, "H5Dclose");
/* First file close */
ret = H5Fclose(fid1);
CHECK(ret, FAIL, "H5Fclose");
/* Second file's get storage size */
ret = H5Dget_storage_size(did2);
CHECK(ret, FAIL, "H5Dget_storage_size");
/* Second file's dataset close */
ret = H5Dclose(did2);
CHECK(ret, FAIL, "H5Dclose");
/* Second file close */
ret = H5Fclose(fid2);
CHECK(ret, FAIL, "H5Fclose");
/*
* Scenario 4
* --trigger H5AC_protect: Assertion `f->shared' failed
* from second call to H5Dset_extent->...H5D__earray_idx_remove->H5EA_get...H5EA__iblock_protect...H5AC_protect
*/
/* First file open */
fid1 = H5Fopen(FILE1, H5F_ACC_RDWR, H5P_DEFAULT);
CHECK(fid1, FAIL, "H5Fopen");
/* First file's dataset open */
did1 = H5Dopen2(fid1, "/dset_ea", H5P_DEFAULT);
CHECK(did1, FAIL, "H5Dopen2");
tid1 = H5Tcopy(did1);
CHECK(tid1, FAIL, "H5Tcopy");
/* Extend the dataset */
ret = H5Dset_extent(did1, e_ext_dims);
CHECK(ret, FAIL, "H5Dset_extent");
/* Write to the dataset */
ret = H5Dwrite(did1, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, e_data);
CHECK(ret, FAIL, "H5Dwrite");
/* Second file open */
fid2 = H5Fopen(FILE1, H5F_ACC_RDWR, H5P_DEFAULT);
CHECK(fid2, FAIL, "H5Fopen");
/* Second file's dataset open */
did2 = H5Dopen2(fid2, "/dset_ea", H5P_DEFAULT );
CHECK(did2, FAIL, "H5Dopen2");
/* First file's dataset close */
ret = H5Dclose(did1);
CHECK(ret, FAIL, "H5Dclose");
/* First file close */
ret = H5Fclose(fid1);
CHECK(ret, FAIL, "H5Fclose");
/* Shrink the dataset */
ret = H5Dset_extent(did2, s_ext_dims);
CHECK(ret, FAIL, "H5Dset_extent");
/* Second file's dataset close */
ret = H5Dclose(did2);
CHECK(ret, FAIL, "H5Dclose");
/* Second file close */
ret = H5Fclose(fid2);
CHECK(ret, FAIL, "H5Fclose");
/* Close the data type */
ret = H5Tclose(tid1);
CHECK(ret, FAIL, "H5Tclose");
} /* end test_file_double_dataset_open() */
/****************************************************************
**
** test_file_double_datatype_open(): low-level file test routine.
@ -3735,6 +4085,8 @@ test_file(void)
test_file_double_group_open(); /* Test opening same group from two files works properly */
test_file_double_dataset_open(); /* Test opening same dataset from two files works properly */
test_file_double_datatype_open(); /* Test opening same named datatype from two files works properly */
test_file_double_file_dataset_open(TRUE);
test_file_double_file_dataset_open(FALSE);
test_userblock_file_size(); /* Tests that files created with a userblock have the correct size */
test_cached_stab_info(); /* Tests that files are created with cached stab info in the superblock */
test_rw_noupdate(); /* Test to ensure that RW permissions don't write the file unless dirtied */