summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2009-09-11 13:27:04 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2009-09-11 13:27:04 (GMT)
commit258d4b38353286ff4066e40048ff90332e7befbe (patch)
treec865c96e436096a35f47c774ebc6599ae7c4006e
parent0b3fbf90899f97a7817779c106e171b89f19a042 (diff)
downloadhdf5-258d4b38353286ff4066e40048ff90332e7befbe.zip
hdf5-258d4b38353286ff4066e40048ff90332e7befbe.tar.gz
hdf5-258d4b38353286ff4066e40048ff90332e7befbe.tar.bz2
[svn-r17464] Description:
Bring r17463 from trunk to 1.8 branch: Add another regression test for userblock+alignment usage, and correct [another] issue with the combination. *sigh* Tested on: FreeBSD/32 6.3 (duty) in debug mode (h5committested on trunk)
-rw-r--r--src/H5FDspace.c7
-rw-r--r--src/H5MFaggr.c58
-rw-r--r--test/tfile.c115
3 files changed, 132 insertions, 48 deletions
diff --git a/src/H5FDspace.c b/src/H5FDspace.c
index 19f9281..9895938 100644
--- a/src/H5FDspace.c
+++ b/src/H5FDspace.c
@@ -126,6 +126,7 @@ H5FD_space_init_interface(void)
static haddr_t
H5FD_extend(H5FD_t *file, H5FD_mem_t type, hbool_t new_block, hsize_t size, haddr_t *frag_addr, hsize_t *frag_size)
{
+ hsize_t orig_size = size; /* Original allocation size */
haddr_t eoa; /* Address of end-of-allocated space */
hsize_t extra; /* Extra space to allocate, to align request */
haddr_t ret_value; /* Return value */
@@ -143,7 +144,7 @@ H5FD_extend(H5FD_t *file, H5FD_mem_t type, hbool_t new_block, hsize_t size, hadd
/* Compute extra space to allocate, if this is a new block and should be aligned */
extra = 0;
- if(new_block && file->alignment > 1 && size >= file->threshold) {
+ if(new_block && file->alignment > 1 && orig_size >= file->threshold) {
hsize_t mis_align; /* Amount EOA is misaligned */
/* Check for EOA already aligned */
@@ -171,6 +172,10 @@ H5FD_extend(H5FD_t *file, H5FD_mem_t type, hbool_t new_block, hsize_t size, hadd
if(file->cls->set_eoa(file, type, eoa) < 0)
HGOTO_ERROR(H5E_VFL, H5E_NOSPACE, HADDR_UNDEF, "file allocation request failed")
+ /* Post-condition sanity check */
+ if(new_block && file->alignment && orig_size >= file->threshold)
+ HDassert(!(ret_value % file->alignment));
+
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_extend() */
diff --git a/src/H5MFaggr.c b/src/H5MFaggr.c
index 1435d18..aa982da 100644
--- a/src/H5MFaggr.c
+++ b/src/H5MFaggr.c
@@ -152,11 +152,9 @@ haddr_t
H5MF_aggr_alloc(H5F_t *f, hid_t dxpl_id, H5F_blk_aggr_t *aggr,
H5F_blk_aggr_t *other_aggr, H5FD_mem_t type, hsize_t size)
{
- hsize_t alignment = 0, mis_align = 0;
- haddr_t frag_addr = 0, eoa_frag_addr = 0;
- hsize_t frag_size = 0, eoa_frag_size = 0;
- haddr_t eoa = 0; /* Initial EOA for the file */
- H5FD_mem_t alloc_type, other_alloc_type;
+ haddr_t eoa_frag_addr = HADDR_UNDEF; /* Address of fragment at EOA */
+ hsize_t eoa_frag_size = 0; /* Size of fragment at EOA */
+ haddr_t eoa = HADDR_UNDEF; /* Initial EOA for the file */
haddr_t ret_value; /* Return value */
FUNC_ENTER_NOAPI(H5MF_aggr_alloc, HADDR_UNDEF)
@@ -174,6 +172,7 @@ HDfprintf(stderr, "%s: type = %u, size = %Hu\n", FUNC, (unsigned)type, size);
HDassert(type >= H5FD_MEM_DEFAULT && type < H5FD_MEM_NTYPES);
HDassert(size > 0);
+ /* Get the EOA for the file */
if(HADDR_UNDEF == (eoa = H5F_get_eoa(f, type)))
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTGET, HADDR_UNDEF, "Unable to get eoa")
@@ -183,29 +182,37 @@ HDfprintf(stderr, "%s: type = %u, size = %Hu\n", FUNC, (unsigned)type, size);
* through H5FD_alloc()
*/
if(f->shared->feature_flags & aggr->feature_flag) {
+ haddr_t aggr_frag_addr = HADDR_UNDEF; /* Address of aggregrator fragment */
+ hsize_t aggr_frag_size = 0; /* Size of aggregator fragment */
+ hsize_t alignment; /* Alignment of this section */
+ hsize_t aggr_mis_align = 0; /* Mis-alignment of aggregator */
+ H5FD_mem_t alloc_type, other_alloc_type;/* Current aggregator & 'other' aggregator types */
+
#ifdef H5MF_AGGR_DEBUG
HDfprintf(stderr, "%s: aggr = {%a, %Hu, %Hu}\n", FUNC, aggr->addr, aggr->tot_size, aggr->size);
#endif /* H5MF_AGGR_DEBUG */
+ /* Turn off alignment if allocation < threshold */
alignment = f->shared->alignment;
if(!((alignment > 1) && (size >= f->shared->threshold)))
alignment = 0; /* no alignment */
- if(alignment && aggr->addr > 0 && aggr->size > 0 && (mis_align = aggr->addr % alignment)) {
- frag_addr = aggr->addr;
- frag_size = alignment - mis_align;
+ /* Generate fragment if aggregator is mis-aligned */
+ if(alignment && aggr->addr > 0 && aggr->size > 0 && (aggr_mis_align = (aggr->addr + H5FD_get_base_addr(f->shared->lf)) % alignment)) {
+ aggr_frag_addr = aggr->addr;
+ aggr_frag_size = alignment - aggr_mis_align;
} /* end if */
alloc_type = aggr->feature_flag == H5FD_FEAT_AGGREGATE_METADATA ? H5FD_MEM_DEFAULT : H5FD_MEM_DRAW;
other_alloc_type = other_aggr->feature_flag == H5FD_FEAT_AGGREGATE_METADATA ? H5FD_MEM_DEFAULT : H5FD_MEM_DRAW;
/* Check if the space requested is larger than the space left in the block */
- if((size + frag_size) > aggr->size) {
+ if((size + aggr_frag_size) > aggr->size) {
htri_t extended = FALSE; /* Whether the file was extended */
/* Check if the block asked for is too large for 'normal' aggregator block */
if(size >= aggr->alloc_size) {
- hsize_t ext_size = size + frag_size;
+ hsize_t ext_size = size + aggr_frag_size;
/* Check for overlapping into file's temporary allocation space */
if(H5F_addr_gt((aggr->addr + aggr->size + ext_size), f->shared->tmp_addr))
@@ -215,7 +222,7 @@ HDfprintf(stderr, "%s: aggr = {%a, %Hu, %Hu}\n", FUNC, aggr->addr, aggr->tot_siz
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, HADDR_UNDEF, "can't extending space")
else if (extended) {
/* aggr->size is unchanged */
- ret_value = aggr->addr + frag_size;
+ ret_value = aggr->addr + aggr_frag_size;
aggr->addr += ext_size;
aggr->tot_size += ext_size;
} else {
@@ -247,8 +254,8 @@ HDfprintf(stderr, "%s: aggr = {%a, %Hu, %Hu}\n", FUNC, aggr->addr, aggr->tot_siz
HDfprintf(stderr, "%s: Allocating block\n", FUNC);
#endif /* H5MF_AGGR_DEBUG */
- if(frag_size > (ext_size - size))
- ext_size += (frag_size - (ext_size - size));
+ if(aggr_frag_size > (ext_size - size))
+ ext_size += (aggr_frag_size - (ext_size - size));
/* Check for overlapping into file's temporary allocation space */
if(H5F_addr_gt((aggr->addr + aggr->size + ext_size), f->shared->tmp_addr))
@@ -257,8 +264,8 @@ HDfprintf(stderr, "%s: Allocating block\n", FUNC);
if((aggr->addr > 0) && (extended = H5FD_try_extend(f->shared->lf, alloc_type, f, aggr->addr + aggr->size, ext_size)) < 0)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, HADDR_UNDEF, "can't extending space")
else if (extended) {
- aggr->addr += frag_size;
- aggr->size += (ext_size - frag_size);
+ aggr->addr += aggr_frag_size;
+ aggr->size += (ext_size - aggr_frag_size);
aggr->tot_size += ext_size;
} else {
haddr_t new_space; /* Address of new space allocated */
@@ -304,19 +311,19 @@ HDfprintf(stderr, "%s: Allocating block\n", FUNC);
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTFREE, HADDR_UNDEF, "can't free eoa fragment")
/* Freeing any possible fragment due to alignment in the block after extension */
- if(extended && frag_size)
- if(H5MF_xfree(f, type, dxpl_id, frag_addr, frag_size) < 0)
+ if(extended && aggr_frag_size)
+ if(H5MF_xfree(f, type, dxpl_id, aggr_frag_addr, aggr_frag_size) < 0)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTFREE, HADDR_UNDEF, "can't free aggregation fragment")
} /* end if */
else {
/* Allocate space out of the block */
- ret_value = aggr->addr + frag_size;
- aggr->size -= (size + frag_size);
- aggr->addr += (size + frag_size);
+ ret_value = aggr->addr + aggr_frag_size;
+ aggr->size -= (size + aggr_frag_size);
+ aggr->addr += (size + aggr_frag_size);
/* free any possible fragment */
- if (frag_size)
- if(H5MF_xfree(f, type, dxpl_id, frag_addr, frag_size) < 0)
+ if(aggr_frag_size)
+ if(H5MF_xfree(f, type, dxpl_id, aggr_frag_addr, aggr_frag_size) < 0)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTFREE, HADDR_UNDEF, "can't free aggregation fragment")
} /* end else */
} /* end if */
@@ -339,13 +346,14 @@ HDfprintf(stderr, "%s: Allocating block\n", FUNC);
/* Sanity check for overlapping into file's temporary allocation space */
HDassert(H5F_addr_le((ret_value + size), f->shared->tmp_addr));
+ /* Post-condition sanity check */
+ if(f->shared->alignment && size >= f->shared->threshold)
+ HDassert(!((ret_value + H5FD_get_base_addr(f->shared->lf)) % f->shared->alignment));
+
done:
#ifdef H5MF_AGGR_DEBUG
HDfprintf(stderr, "%s: ret_value = %a\n", FUNC, ret_value);
#endif /* H5MF_AGGR_DEBUG */
-
- if(alignment)
- HDassert(!(ret_value % alignment));
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5MF_aggr_alloc() */
diff --git a/test/tfile.c b/test/tfile.c
index b291154..3d730d5 100644
--- a/test/tfile.c
+++ b/test/tfile.c
@@ -2117,7 +2117,7 @@ test_rw_noupdate(void)
/****************************************************************
**
-** test_userblock_alignment_helper(): helper routine for
+** test_userblock_alignment_helper1(): helper routine for
** test_userblock_alignment() test, to handle common testing
**
** Programmer: Quincey Koziol
@@ -2126,7 +2126,7 @@ test_rw_noupdate(void)
**
*****************************************************************/
static int
-test_userblock_alignment_helper(hid_t fcpl, hid_t fapl)
+test_userblock_alignment_helper1(hid_t fcpl, hid_t fapl)
{
hid_t fid; /* File ID */
int curr_num_errs = GetTestNumErrs(); /* Retrieve the current # of errors */
@@ -2174,16 +2174,35 @@ test_userblock_alignment_helper(hid_t fcpl, hid_t fapl)
CHECK(ret, FAIL, "H5Fclose");
} /* end if */
+ return((GetTestNumErrs() == curr_num_errs) ? 0 : -1);
+} /* end test_userblock_alignment_helper1() */
+
+/****************************************************************
+**
+** test_userblock_alignment_helper2(): helper routine for
+** test_userblock_alignment() test, to handle common testing
+**
+** Programmer: Quincey Koziol
+** koziol@hdfgroup.org
+** Septmber 10, 2009
+**
+*****************************************************************/
+static int
+test_userblock_alignment_helper2(hid_t fapl, hbool_t open_rw)
+{
+ hid_t fid; /* File ID */
+ int curr_num_errs = GetTestNumErrs(); /* Retrieve the current # of errors */
+ herr_t ret; /* Generic return value */
/* Re-open file */
- fid = H5Fopen(FILE1, H5F_ACC_RDWR, fapl);
+ fid = H5Fopen(FILE1, (open_rw ? H5F_ACC_RDWR : H5F_ACC_RDONLY), fapl);
CHECK(fid, FAIL, "H5Fopen");
/* Only proceed further if file ID is OK */
if(fid > 0) {
- hid_t gid, gid2; /* Group IDs */
- hid_t did; /* Dataset ID */
- int val = 2; /* Dataset value */
+ hid_t gid; /* Group ID */
+ hid_t did; /* Dataset ID */
+ int val = -1; /* Dataset value */
/* Open group */
gid = H5Gopen2(fid, "group1", H5P_DEFAULT);
@@ -2202,13 +2221,18 @@ test_userblock_alignment_helper(hid_t fcpl, hid_t fapl)
ret = H5Dclose(did);
CHECK(ret, FAIL, "H5Dclose");
- /* Create a new group */
- gid2 = H5Gcreate2(gid, "group2", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
- CHECK(gid, FAIL, "H5Gcreate2");
+ /* Only create new objects if file is open R/W */
+ if(open_rw) {
+ hid_t gid2; /* Group ID */
- /* Close new group */
- ret = H5Gclose(gid2);
- CHECK(ret, FAIL, "H5Gclose");
+ /* Create a new group */
+ gid2 = H5Gcreate2(gid, "group2", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ CHECK(gid, FAIL, "H5Gcreate2");
+
+ /* Close new group */
+ ret = H5Gclose(gid2);
+ CHECK(ret, FAIL, "H5Gclose");
+ } /* end if */
/* Close group */
ret = H5Gclose(gid);
@@ -2220,7 +2244,7 @@ test_userblock_alignment_helper(hid_t fcpl, hid_t fapl)
} /* end if */
return((GetTestNumErrs() == curr_num_errs) ? 0 : -1);
-} /* end test_userblock_alignment_helper() */
+} /* end test_userblock_alignment_helper2() */
/****************************************************************
**
@@ -2261,9 +2285,11 @@ test_userblock_alignment(void)
ret = H5Pset_alignment(fapl, (hsize_t)1, (hsize_t)3);
CHECK(ret, FAIL, "H5Pset_alignment");
- /* Call helper routine to perform file manipulations */
- ret = test_userblock_alignment_helper(fcpl, fapl);
- CHECK(ret, FAIL, "test_userblock_alignment_helper");
+ /* Call helper routines to perform file manipulations */
+ ret = test_userblock_alignment_helper1(fcpl, fapl);
+ CHECK(ret, FAIL, "test_userblock_alignment_helper1");
+ ret = test_userblock_alignment_helper2(fapl, TRUE);
+ CHECK(ret, FAIL, "test_userblock_alignment_helper2");
/* Release property lists */
ret = H5Pclose(fcpl);
@@ -2290,9 +2316,11 @@ test_userblock_alignment(void)
ret = H5Pset_alignment(fapl, (hsize_t)1, (hsize_t)16);
CHECK(ret, FAIL, "H5Pset_alignment");
- /* Call helper routine to perform file manipulations */
- ret = test_userblock_alignment_helper(fcpl, fapl);
- CHECK(ret, FAIL, "test_userblock_alignment_helper");
+ /* Call helper routines to perform file manipulations */
+ ret = test_userblock_alignment_helper1(fcpl, fapl);
+ CHECK(ret, FAIL, "test_userblock_alignment_helper1");
+ ret = test_userblock_alignment_helper2(fapl, TRUE);
+ CHECK(ret, FAIL, "test_userblock_alignment_helper2");
/* Release property lists */
ret = H5Pclose(fcpl);
@@ -2319,9 +2347,11 @@ test_userblock_alignment(void)
ret = H5Pset_alignment(fapl, (hsize_t)1, (hsize_t)512);
CHECK(ret, FAIL, "H5Pset_alignment");
- /* Call helper routine to perform file manipulations */
- ret = test_userblock_alignment_helper(fcpl, fapl);
- CHECK(ret, FAIL, "test_userblock_alignment_helper");
+ /* Call helper routines to perform file manipulations */
+ ret = test_userblock_alignment_helper1(fcpl, fapl);
+ CHECK(ret, FAIL, "test_userblock_alignment_helper1");
+ ret = test_userblock_alignment_helper2(fapl, TRUE);
+ CHECK(ret, FAIL, "test_userblock_alignment_helper2");
/* Release property lists */
ret = H5Pclose(fcpl);
@@ -2392,6 +2422,47 @@ test_userblock_alignment(void)
CHECK(ret, FAIL, "H5Pclose");
ret = H5Pclose(fapl);
CHECK(ret, FAIL, "H5Pclose");
+
+
+ /* Case 6:
+ * File created with:
+ * Userblock size = 512, alignment = 512
+ * File re-opened for read-only & read-write access with:
+ * Userblock size = 512, alignment = 1024
+ * Outcome:
+ * Should succeed
+ */
+ /* Create file creation property list with user block */
+ fcpl = H5Pcreate(H5P_FILE_CREATE);
+ CHECK(fcpl, FAIL, "H5Pcreate");
+ ret = H5Pset_userblock(fcpl, (hsize_t)512);
+ CHECK(ret, FAIL, "H5Pset_userblock");
+
+ /* Create file access property list with alignment */
+ fapl = H5Pcreate(H5P_FILE_ACCESS);
+ CHECK(fapl, FAIL, "H5Pcreate");
+ ret = H5Pset_alignment(fapl, (hsize_t)1, (hsize_t)512);
+ CHECK(ret, FAIL, "H5Pset_alignment");
+
+ /* Call helper routines to perform file manipulations */
+ ret = test_userblock_alignment_helper1(fcpl, fapl);
+ CHECK(ret, FAIL, "test_userblock_alignment_helper1");
+
+ /* Change alignment in FAPL */
+ ret = H5Pset_alignment(fapl, (hsize_t)1, (hsize_t)1024);
+ CHECK(ret, FAIL, "H5Pset_alignment");
+
+ /* Call helper routines to perform file manipulations */
+ ret = test_userblock_alignment_helper2(fapl, FALSE);
+ CHECK(ret, FAIL, "test_userblock_alignment_helper2");
+ ret = test_userblock_alignment_helper2(fapl, TRUE);
+ CHECK(ret, FAIL, "test_userblock_alignment_helper2");
+
+ /* Release property lists */
+ ret = H5Pclose(fcpl);
+ CHECK(ret, FAIL, "H5Pclose");
+ ret = H5Pclose(fapl);
+ CHECK(ret, FAIL, "H5Pclose");
} /* end test_userblock_alignment() */
/****************************************************************