summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/H5BT.c153
-rw-r--r--src/H5BTprivate.h2
-rw-r--r--test/blocktrack.c282
3 files changed, 437 insertions, 0 deletions
diff --git a/src/H5BT.c b/src/H5BT.c
index 4e76278..c0a5510 100644
--- a/src/H5BT.c
+++ b/src/H5BT.c
@@ -449,3 +449,156 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5BT_get_total_size() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5BT_remove_find_cb
+ *
+ * Purpose: v2 B-tree find callback
+ *
+ * Return: Success: 0
+ *
+ * Failure: 1
+ *
+ * Programmer: Quincey Koziol
+ * Friday, March 11, 2005
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+H5BT_remove_find_cb(const void *_record, void *_op_data)
+{
+ const H5BT_blk_info_t *record = (const H5BT_blk_info_t *)_record;
+ H5BT_blk_info_t *search = (H5BT_blk_info_t *)_op_data;
+
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5BT_remove_find_cb)
+
+ /* Copy the data out */
+ *search = *record;
+
+ FUNC_LEAVE_NOAPI(0);
+} /* end H5BT_remove_find_cb() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5BT_remove
+ *
+ * Purpose: Remove a block (offset/length) from a block tracker.
+ *
+ * Return: Non-negative on success, negative on failure
+ *
+ * Programmer: Quincey Koziol
+ * koziol@ncsa.uiuc.edu
+ * Mar 11 2005
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5BT_remove(H5F_t *f, hid_t dxpl_id, haddr_t addr, haddr_t offset, hsize_t length)
+{
+ H5BT_t *bt = NULL; /* The new B-tree header information */
+ H5BT_blk_info_t found; /* Block info found */
+ hsize_t nblks; /* Number of blocks tracked */
+ herr_t ret_value=SUCCEED;
+
+ FUNC_ENTER_NOAPI(H5BT_remove, FAIL)
+
+ /*
+ * Check arguments.
+ */
+ HDassert(f);
+ HDassert(H5F_addr_defined(addr));
+
+ /* Look up the block tracker header */
+ if (NULL == (bt = H5AC_protect(f, dxpl_id, H5AC_BLTR, addr, NULL, NULL, H5AC_WRITE)))
+ HGOTO_ERROR(H5E_BLKTRK, H5E_CANTPROTECT, FAIL, "unable to load block tracker info")
+
+ /* Check for block at this address already */
+ if (H5B2_find(f, dxpl_id, H5B2_BLKTRK, bt->bt2_addr, &offset, H5BT_remove_find_cb, &found) < 0) {
+ /* Clear any errors from H5B2_find() */
+ H5E_clear_stack(NULL);
+
+ /* Find next block lower */
+HDfprintf(stderr,"%s: Need to search for lower & upper block!\n",FUNC);
+HGOTO_ERROR(H5E_BLKTRK, H5E_UNSUPPORTED, FAIL, "Couldn't find block to remove")
+ } /* end if */
+ else {
+ /* Found block at address */
+
+ /* Check for exact fit */
+ if(found.len == length) {
+ /* Delete recode from B-tree */
+ if(H5B2_remove(f, dxpl_id, H5B2_BLKTRK, bt->bt2_addr, &found)<0)
+ HGOTO_ERROR(H5E_BLKTRK, H5E_CANTDELETE, FAIL, "can't remove block")
+
+ /* Determine the number of blocks being tracked */
+ if(H5B2_get_nrec(f, dxpl_id, H5B2_BLKTRK, bt->bt2_addr, &nblks) < 0)
+ HGOTO_ERROR(H5E_BLKTRK, H5E_CANTINSERT, FAIL, "unable to determine # of blocks")
+
+ /* Check for no blocks left */
+ if(nblks == 0) {
+ bt->max_block_size = 0; /* Indicate that the value is invalid */
+ bt->max_block_cnt = 0;
+ bt->min_block_size = HSIZET_MAX; /* Indicate that the value is invalid */
+ bt->min_block_cnt = 0;
+ bt->status = 0;
+ } /* end if */
+ else {
+ /* Update max. block metadata */
+ if(found.len == bt->max_block_size) {
+ /* Decrement maximum block count */
+ bt->max_block_cnt--;
+
+ /* Check if we don't know the maximum size any longer */
+ if(bt->max_block_cnt==0) {
+ if(bt->min_block_size < HSIZET_MAX) {
+ bt->max_block_size = bt->min_block_size;
+ bt->max_block_cnt = bt->min_block_cnt;
+ } /* end if */
+ else
+ bt->max_block_size = 0;
+ bt->status &= ~H5BT_STATUS_MAX_VALID;
+ } /* end if */
+ } /* end if */
+
+ /* Update min. block metadata */
+ if(found.len == bt->min_block_size) {
+ /* Decrement minimum block count */
+ bt->min_block_cnt--;
+
+ /* Check if we don't know the minimum size any longer */
+ if(bt->min_block_cnt==0) {
+ if(bt->max_block_size > 0) {
+ bt->min_block_size = bt->max_block_size;
+ bt->min_block_cnt = bt->max_block_cnt;
+ } /* end if */
+ else
+ bt->min_block_size = HSIZET_MAX;
+ bt->status &= ~H5BT_STATUS_MIN_VALID;
+ } /* end if */
+ } /* end if */
+ } /* end else */
+
+ /* Decrement total amount of blocks tracked */
+ bt->tot_block_size -= length;
+ } /* end if */
+ else if(found.len > length) {
+HDfprintf(stderr,"%s: found={%a/%Hu}\n",FUNC,found.addr,found.len);
+HGOTO_ERROR(H5E_BLKTRK, H5E_UNSUPPORTED, FAIL, "Couldn't find block to remove")
+ } /* end if */
+ else {
+ /* Check for blocks at higher address, if necessary */
+HDfprintf(stderr,"%s: found={%a/%Hu}\n",FUNC,found.addr,found.len);
+HGOTO_ERROR(H5E_BLKTRK, H5E_UNSUPPORTED, FAIL, "Couldn't find block to remove")
+ } /* end else */
+ } /* end else */
+
+done:
+ /* Release the block tracker info */
+ if (bt && H5AC_unprotect(f, dxpl_id, H5AC_BLTR, addr, bt, H5AC__NO_FLAGS_SET) < 0)
+ HDONE_ERROR(H5E_BLKTRK, H5E_CANTUNPROTECT, FAIL, "unable to release block tracker info")
+
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5BT_remove() */
+
diff --git a/src/H5BTprivate.h b/src/H5BTprivate.h
index a5805ac..48d5384 100644
--- a/src/H5BTprivate.h
+++ b/src/H5BTprivate.h
@@ -48,6 +48,8 @@
H5_DLL herr_t H5BT_create(H5F_t *f, hid_t dxpl_id, haddr_t *addr_p);
H5_DLL herr_t H5BT_insert(H5F_t *f, hid_t dxpl_id, haddr_t addr, haddr_t offset,
hsize_t length);
+H5_DLL herr_t H5BT_remove(H5F_t *f, hid_t dxpl_id, haddr_t addr, haddr_t offset,
+ hsize_t length);
H5_DLL herr_t H5BT_get_total_size(H5F_t *f, hid_t dxpl_id, haddr_t addr,
hsize_t *tot_size);
diff --git a/test/blocktrack.c b/test/blocktrack.c
index 224de78..b2f1937 100644
--- a/test/blocktrack.c
+++ b/test/blocktrack.c
@@ -875,6 +875,285 @@ error:
/*-------------------------------------------------------------------------
+ * Function: test_remove_whole
+ *
+ * Purpose: Basic tests for the block tracker code
+ *
+ * Return: Success: 0
+ *
+ * Failure: 1
+ *
+ * Programmer: Quincey Koziol
+ * Friday, March 11, 2005
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+test_remove_whole(hid_t fapl)
+{
+ hid_t file=-1;
+ char filename[1024];
+ H5F_t *f=NULL;
+ haddr_t bt_addr; /* Address of block tracker created */
+ hsize_t tot_size; /* Total size of blocks tracked */
+ hsize_t max_size; /* Max. size of blocks tracked */
+ uint32_t max_count; /* Ref. count of max. size of blocks tracked */
+ hbool_t max_valid; /* Is max. size valid over all blocks? */
+ hsize_t min_size; /* Min. size of blocks tracked */
+ uint32_t min_count; /* Ref. count of min. size of blocks tracked */
+ hbool_t min_valid; /* Is min. size valid over all blocks? */
+
+ h5_fixname(FILENAME[0], fapl, filename, sizeof filename);
+
+ /* Create the file to work on */
+ if ((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) TEST_ERROR;
+
+ /* Get a pointer to the internal file object */
+ if (NULL==(f=H5I_object(file))) {
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ TEST_ERROR;
+ } /* end if */
+
+ if (H5BT_create(f, H5P_DATASET_XFER_DEFAULT, &bt_addr/*out*/)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+
+ /* Insert several blocks */
+ if (H5BT_insert(f, H5P_DATASET_XFER_DEFAULT, bt_addr, (haddr_t)50, (hsize_t)20)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+
+ if (H5BT_insert(f, H5P_DATASET_XFER_DEFAULT, bt_addr, (haddr_t)100, (hsize_t)15)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+
+ if (H5BT_insert(f, H5P_DATASET_XFER_DEFAULT, bt_addr, (haddr_t)150, (hsize_t)15)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+
+ if (H5BT_insert(f, H5P_DATASET_XFER_DEFAULT, bt_addr, (haddr_t)200, (hsize_t)35)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+
+ if (H5BT_insert(f, H5P_DATASET_XFER_DEFAULT, bt_addr, (haddr_t)250, (hsize_t)35)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+
+ /*
+ * Test removing blocks
+ */
+ TESTING("remove entire block, in middle of block size range");
+ if (H5BT_remove(f, H5P_DATASET_XFER_DEFAULT, bt_addr, (haddr_t)50, (hsize_t)20)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+
+ if (H5BT_get_total_size(f, H5P_DATASET_XFER_DEFAULT, bt_addr, &tot_size)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+ /* Make certain that the size is correct */
+ if(tot_size != 100) TEST_ERROR;
+
+ if (H5BT_get_max_info(f, H5P_DATASET_XFER_DEFAULT, bt_addr, &max_size, &max_count, &max_valid)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+ /* Make certain that the max. info is correct */
+ if(max_size != 35) TEST_ERROR;
+ if(max_count != 2) TEST_ERROR;
+ if(max_valid != 1) TEST_ERROR;
+
+ if (H5BT_get_min_info(f, H5P_DATASET_XFER_DEFAULT, bt_addr, &min_size, &min_count, &min_valid)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+ /* Make certain that the min. info is correct */
+ if(min_size != 15) TEST_ERROR;
+ if(min_count != 2) TEST_ERROR;
+ if(min_valid != 1) TEST_ERROR;
+
+ PASSED();
+
+ TESTING("remove entire block, at bottom of block size range");
+
+ /* Remove first block at min. size */
+ if (H5BT_remove(f, H5P_DATASET_XFER_DEFAULT, bt_addr, (haddr_t)100, (hsize_t)15)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+
+ if (H5BT_get_total_size(f, H5P_DATASET_XFER_DEFAULT, bt_addr, &tot_size)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+ /* Make certain that the size is correct */
+ if(tot_size != 85) TEST_ERROR;
+
+ if (H5BT_get_max_info(f, H5P_DATASET_XFER_DEFAULT, bt_addr, &max_size, &max_count, &max_valid)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+ /* Make certain that the max. info is correct */
+ if(max_size != 35) TEST_ERROR;
+ if(max_count != 2) TEST_ERROR;
+ if(max_valid != 1) TEST_ERROR;
+
+ if (H5BT_get_min_info(f, H5P_DATASET_XFER_DEFAULT, bt_addr, &min_size, &min_count, &min_valid)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+ /* Make certain that the min. info is correct */
+ if(min_size != 15) TEST_ERROR;
+ if(min_count != 1) TEST_ERROR;
+ if(min_valid != 1) TEST_ERROR;
+
+ /* Remove last block at min. size */
+ if (H5BT_remove(f, H5P_DATASET_XFER_DEFAULT, bt_addr, (haddr_t)150, (hsize_t)15)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+
+ if (H5BT_get_total_size(f, H5P_DATASET_XFER_DEFAULT, bt_addr, &tot_size)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+ /* Make certain that the size is correct */
+ if(tot_size != 70) TEST_ERROR;
+
+ if (H5BT_get_max_info(f, H5P_DATASET_XFER_DEFAULT, bt_addr, &max_size, &max_count, &max_valid)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+ /* Make certain that the max. info is correct */
+ if(max_size != 35) TEST_ERROR;
+ if(max_count != 2) TEST_ERROR;
+ if(max_valid != 1) TEST_ERROR;
+
+ if (H5BT_get_min_info(f, H5P_DATASET_XFER_DEFAULT, bt_addr, &min_size, &min_count, &min_valid)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+ /* Make certain that the min. info is correct */
+ if(min_size != 35) TEST_ERROR;
+ if(min_count != 2) TEST_ERROR;
+ if(min_valid != 0) TEST_ERROR;
+
+ PASSED();
+
+ TESTING("remove entire block, at top of block size range");
+
+ /* Remove first block at max. size */
+ if (H5BT_remove(f, H5P_DATASET_XFER_DEFAULT, bt_addr, (haddr_t)200, (hsize_t)35)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+
+ if (H5BT_get_total_size(f, H5P_DATASET_XFER_DEFAULT, bt_addr, &tot_size)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+ /* Make certain that the size is correct */
+ if(tot_size != 35) TEST_ERROR;
+
+ if (H5BT_get_max_info(f, H5P_DATASET_XFER_DEFAULT, bt_addr, &max_size, &max_count, &max_valid)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+ /* Make certain that the max. info is correct */
+ if(max_size != 35) TEST_ERROR;
+ if(max_count != 1) TEST_ERROR;
+ if(max_valid != 1) TEST_ERROR;
+
+ if (H5BT_get_min_info(f, H5P_DATASET_XFER_DEFAULT, bt_addr, &min_size, &min_count, &min_valid)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+ /* Make certain that the min. info is correct */
+ if(min_size != 35) TEST_ERROR;
+ if(min_count != 1) TEST_ERROR;
+ if(min_valid != 0) TEST_ERROR;
+
+ /* Remove last block at max. size */
+ if (H5BT_remove(f, H5P_DATASET_XFER_DEFAULT, bt_addr, (haddr_t)250, (hsize_t)35)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+
+ if (H5BT_get_total_size(f, H5P_DATASET_XFER_DEFAULT, bt_addr, &tot_size)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+ /* Make certain that the size is correct */
+ if(tot_size != 0) TEST_ERROR;
+
+ if (H5BT_get_max_info(f, H5P_DATASET_XFER_DEFAULT, bt_addr, &max_size, &max_count, &max_valid)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+ /* Make certain that the max. info is correct */
+ if(max_size != 0) TEST_ERROR;
+ if(max_count != 0) TEST_ERROR;
+ if(max_valid != 0) TEST_ERROR;
+
+ if (H5BT_get_min_info(f, H5P_DATASET_XFER_DEFAULT, bt_addr, &min_size, &min_count, &min_valid)<0) {
+ H5_FAILED();
+ H5Eprint_stack(H5E_DEFAULT, stdout);
+ goto error;
+ } /* end if */
+ /* Make certain that the min. info is correct */
+ if(min_size != HSIZET_MAX) TEST_ERROR;
+ if(min_count != 0) TEST_ERROR;
+ if(min_valid != 0) TEST_ERROR;
+
+ PASSED();
+
+ if (H5Fclose(file)<0) TEST_ERROR;
+
+ return 0;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Fclose(file);
+ } H5E_END_TRY;
+ return 1;
+} /* test_remove_whole() */
+
+
+/*-------------------------------------------------------------------------
* Function: main
*
* Purpose: Test the block tracker code
@@ -910,6 +1189,9 @@ main(void)
nerrors += test_insert_overlap(fapl);
nerrors += test_insert_merge(fapl);
+ /* Test block tracker removal */
+ nerrors += test_remove_whole(fapl);
+
if (nerrors) goto error;
puts("All block tracker tests passed.");
#ifndef QAK