From f99a4120573eb8bcededc20a91be8fa520d4ebfa Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Tue, 23 Apr 2002 11:01:43 -0500 Subject: [svn-r5230] Purpose: Code cleanup Description: Clean up the H5B_iterate code to not have a single hard-wired iterator for each interface which uses a B-tree, instead accept a function pointer which determines the callback function. This allows additional iterator callbacks to be defined without requiring additional H5B functions to be created. In that spirit, remove the H5B_prune_by_extent call and convert the H5F_istore callback routine for it into a callback routine for H5B_iterate. Platforms tested: FreeBSD 4.5 (sleipnir) --- src/H5B.c | 124 +++------------------------------------------------ src/H5Bprivate.h | 20 +++------ src/H5Distore.c | 133 +++++++++++++++++++++++++++++++------------------------ src/H5Fistore.c | 133 +++++++++++++++++++++++++++++++------------------------ src/H5G.c | 2 +- src/H5Gnode.c | 9 ++-- src/H5Gpkg.h | 3 ++ 7 files changed, 173 insertions(+), 251 deletions(-) diff --git a/src/H5B.c b/src/H5B.c index b1edd37..4db91b0 100644 --- a/src/H5B.c +++ b/src/H5B.c @@ -1568,10 +1568,13 @@ H5B_insert_helper(H5F_t *f, haddr_t addr, const H5B_class_t *type, * * Robb Matzke, 1999-07-28 * The ADDR argument is passed by value. + * + * Quincey Koziol, 2002-04-22 + * Changed callback to function pointer from static function *------------------------------------------------------------------------- */ herr_t -H5B_iterate (H5F_t *f, const H5B_class_t *type, haddr_t addr, void *udata) +H5B_iterate (H5F_t *f, const H5B_class_t *type, H5B_operator_t op, haddr_t addr, void *udata) { H5B_t *bt = NULL; haddr_t next_addr; @@ -1588,7 +1591,7 @@ H5B_iterate (H5F_t *f, const H5B_class_t *type, haddr_t addr, void *udata) */ assert(f); assert(type); - assert(type->list); + assert(op); assert(H5F_addr_defined(addr)); assert(udata); @@ -1598,7 +1601,7 @@ H5B_iterate (H5F_t *f, const H5B_class_t *type, haddr_t addr, void *udata) } if (bt->level > 0) { /* Keep following the left-most child until we reach a leaf node. */ - if ((ret_value=H5B_iterate(f, type, bt->child[0], udata))<0) { + if ((ret_value=H5B_iterate(f, type, op, bt->child[0], udata))<0) { HGOTO_ERROR(H5E_BTREE, H5E_CANTLIST, FAIL, "unable to list B-tree node"); } @@ -1641,7 +1644,7 @@ H5B_iterate (H5F_t *f, const H5B_class_t *type, haddr_t addr, void *udata) * application callback. */ for (i=0, ret_value=0; ilist)(f, key+i*type->sizeof_nkey, + ret_value = (*op)(f, key+i*type->sizeof_nkey, child[i], key+(i+1)*type->sizeof_nkey, udata); if (ret_value<0) { @@ -2153,119 +2156,6 @@ done: /*------------------------------------------------------------------------- - * Function: H5B_prune_by_extent - * - * Purpose: Search for chunks that are no longer necessary in the B-tree. - * The function iterates through the B-tree and calls an operator - * function prune_extent - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: March 26, 2002 - * - * Comments: Private function - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -herr_t -H5B_prune_by_extent(H5F_t *f, const H5B_class_t *type, haddr_t addr, - void *udata, hsize_t *size) -{ - H5B_t *bt = NULL; - haddr_t next_addr; - haddr_t cur_addr = HADDR_UNDEF; - uint8_t *key = NULL; - int i, nchildren; - herr_t ret_value = FAIL; - - FUNC_ENTER(H5B_prune_by_extent, FAIL); - -/* - * Check arguments. - */ - assert(f); - assert(type); - assert(type->prune_extent); - assert(H5F_addr_defined(addr)); - assert(udata); - - if(NULL == (bt = H5AC_find(f, H5AC_BT, addr, type, udata))) { - HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, - "unable to load B-tree node"); - } - - if(bt->level > 0) { - /* Keep following the left-most child until we reach a leaf node. */ - if((ret_value = - H5B_prune_by_extent(f, type, bt->child[0], udata, - size)) < 0) { - HGOTO_ERROR(H5E_BTREE, H5E_CANTLIST, FAIL, - "unable to list B-tree node"); - } - } - else { - -/* - * We've reached the left-most leaf. Now follow the right-sibling - * pointer from leaf to leaf until we've processed all leaves. - */ - - if(NULL == (key = - H5MM_malloc((2 * H5B_Kvalue(f, - type) + 1) * type->sizeof_nkey))) { - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, - "memory allocation failed"); - } - - for(cur_addr = addr, ret_value = 0; - H5F_addr_defined(cur_addr) && !ret_value; - cur_addr = next_addr) { - - /* - * Save all the native keys since we can't leave the B-tree node protected during an application callback. - */ - - if(NULL == (bt = H5AC_find(f, H5AC_BT, cur_addr, type, udata))) { - HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "B-tree node"); - } - - for(i = 0; i < bt->nchildren + 1; i++) { - if(!bt->key[i].nkey) - H5B_decode_key(f, bt, i); - HDmemcpy(key + i * type->sizeof_nkey, bt->key[i].nkey, - type->sizeof_nkey); - } - - next_addr = bt->right; - nchildren = bt->nchildren; - bt = NULL; - - /* Figure out what chunks are no longer in use for the specified extent and release them */ - - for(i = 0, ret_value = 0; i < nchildren && !ret_value; i++) { - ret_value = - (type->prune_extent) (f, key + i * type->sizeof_nkey, - addr, udata, size); - if(ret_value < 0) { - HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, FAIL, - "iterator function failed"); - } - } /*i */ - } /*addr */ - } /*level */ - -done: - if(key != NULL) - H5MM_xfree(key); - FUNC_LEAVE(ret_value); -} - - -/*------------------------------------------------------------------------- * Function: H5B_debug * * Purpose: Prints debugging info about a B-tree. diff --git a/src/H5Bprivate.h b/src/H5Bprivate.h index e6fc2ac..0d509d6 100644 --- a/src/H5Bprivate.h +++ b/src/H5Bprivate.h @@ -50,6 +50,10 @@ typedef enum H5B_ins_t { H5B_INS_REMOVE = 5 /*remove current node */ } H5B_ins_t; +/* Define the operator callback function pointer for H5B_iterate() */ +typedef herr_t (*H5B_operator_t)(H5F_t *f, void *_lt_key, haddr_t addr, + void *_rt_key, void *_udata); + /* * Each class of object that can be pointed to by a B-link tree has a * variable of this type that contains class variables and methods. Each @@ -80,20 +84,11 @@ typedef struct H5B_class_t { H5B_ins_t (*remove)(H5F_t*, haddr_t, void*, hbool_t*, void*, void*, hbool_t*); - /* iterate through the leaf nodes */ - herr_t (*list)(H5F_t*, void*, haddr_t, void*, void*); - /* encode, decode, debug key values */ herr_t (*decode)(H5F_t*, struct H5B_t*, uint8_t*, void*); herr_t (*encode)(H5F_t*, struct H5B_t*, uint8_t*, void*); herr_t (*debug_key)(FILE*, int, int, const void*, const void*); - /*pvn */ - - /* iterate through the leaf nodes, removing chunks upon H5Dset_extend request */ - herr_t (*prune_extent)( H5F_t *f, void *_lt_key, haddr_t addr, - void *_udata, hsize_t *size ); - } H5B_class_t; /* @@ -136,11 +131,8 @@ __DLL__ herr_t H5B_insert (H5F_t *f, const H5B_class_t *type, haddr_t addr, const double split_ratios[], void *udata); __DLL__ herr_t H5B_remove(H5F_t *f, const H5B_class_t *type, haddr_t addr, void *udata); -__DLL__ herr_t H5B_iterate (H5F_t *f, const H5B_class_t *type, haddr_t addr, - void *udata); +__DLL__ herr_t H5B_iterate (H5F_t *f, const H5B_class_t *type, H5B_operator_t + op, haddr_t addr, void *udata); __DLL__ int H5B_Kvalue(H5F_t *f, const H5B_class_t *type); -__DLL__ herr_t H5B_prune_by_extent( H5F_t *f, const H5B_class_t *type, haddr_t addr, - void *udata, hsize_t *size ); - #endif diff --git a/src/H5Distore.c b/src/H5Distore.c index d2cb490..54b2fd2 100644 --- a/src/H5Distore.c +++ b/src/H5Distore.c @@ -120,7 +120,9 @@ static H5B_ins_t H5F_istore_insert(H5F_t *f, haddr_t addr, void *_lt_key, void *_udata, void *_rt_key, hbool_t *rt_key_changed, haddr_t *new_node/*out*/); -static herr_t H5F_istore_iterate(H5F_t *f, void *left_key, haddr_t addr, +static herr_t H5F_istore_iter_allocated(H5F_t *f, void *left_key, haddr_t addr, + void *right_key, void *_udata); +static herr_t H5F_istore_iter_dump(H5F_t *f, void *left_key, haddr_t addr, void *right_key, void *_udata); static herr_t H5F_istore_decode_key(H5F_t *f, H5B_t *bt, uint8_t *raw, void *_key); @@ -130,15 +132,11 @@ static herr_t H5F_istore_debug_key(FILE *stream, int indent, int fwidth, const void *key, const void *udata); static haddr_t H5F_istore_get_addr(H5F_t *f, const H5O_layout_t *layout, const hssize_t offset[]); - -static herr_t H5F_istore_prune_extent( H5F_t *f, void *left_key, haddr_t addr, - void *_udata, hsize_t *size ); -static H5B_ins_t H5F_istore_remove( H5F_t *f, haddr_t addr, - void *_lt_key /*in,out*/, - hbool_t *lt_key_changed /*out*/, - void UNUSED *_udata /*in,out*/, - void UNUSED *_rt_key /*in,out*/, - hbool_t *rt_key_changed /*out*/); +static herr_t H5F_istore_prune_extent(H5F_t *f, void *_lt_key, haddr_t addr, + void *_rt_key, void *_udata); +static H5B_ins_t H5F_istore_remove( H5F_t *f, haddr_t addr, void *_lt_key, + hbool_t *lt_key_changed, void *_udata, void *_rt_key, + hbool_t *rt_key_changed); /* * B-tree key. A key contains the minimum logical N-dimensional address and @@ -166,6 +164,7 @@ typedef struct H5F_istore_ud1_t { H5O_layout_t mesg; /*layout message */ hsize_t total_storage; /*output from iterator */ FILE *stream; /*debug output stream */ + hsize_t *dims; /*dataset dimensions */ } H5F_istore_ud1_t; /* inherits B-tree like properties from H5B */ @@ -181,11 +180,9 @@ H5B_class_t H5B_ISTORE[1] = {{ FALSE, /*follow min branch? */ FALSE, /*follow max branch? */ H5F_istore_remove, /*remove */ - H5F_istore_iterate, /*iterator */ H5F_istore_decode_key, /*decode */ H5F_istore_encode_key, /*encode */ H5F_istore_debug_key, /*debug */ - H5F_istore_prune_extent, /*remove chunks, upon H5Dset_extend call */ }}; #define H5F_HASH_DIVISOR 8 /* Attempt to spread out the hashing */ @@ -840,11 +837,44 @@ H5F_istore_insert(H5F_t *f, haddr_t addr, void *_lt_key, /*------------------------------------------------------------------------- - * Function: H5F_istore_iterate + * Function: H5F_istore_iter_allocated + * + * Purpose: Simply counts the number of chunks for a dataset. + * + * Return: Success: Non-negative + * + * Failure: Negative + * + * Programmer: Robb Matzke + * Wednesday, April 21, 1999 + * + * Modifications: + * Robb Matzke, 1999-07-28 + * The ADDR argument is passed by value. + * + * Quincey Koziol, 2002-04-22 + * Changed to callback from H5B_iterate + *------------------------------------------------------------------------- + */ +static herr_t +H5F_istore_iter_allocated (H5F_t UNUSED *f, void *_lt_key, haddr_t UNUSED addr, + void UNUSED *_rt_key, void *_udata) +{ + H5F_istore_ud1_t *bt_udata = (H5F_istore_ud1_t *)_udata; + H5F_istore_key_t *lt_key = (H5F_istore_key_t *)_lt_key; + + FUNC_ENTER(H5F_istore_iterate, FAIL); + + bt_udata->total_storage += lt_key->nbytes; + FUNC_LEAVE(SUCCEED); +} /* H5F_istore_iter_allocated() */ + + +/*------------------------------------------------------------------------- + * Function: H5F_istore_iter_dump * - * Purpose: Simply counts the number of chunks for a dataset. If the - * UDATA.STREAM member is non-null then debugging information is - * written to that stream. + * Purpose: If the UDATA.STREAM member is non-null then debugging + * information is written to that stream. * * Return: Success: Non-negative * @@ -856,10 +886,13 @@ H5F_istore_insert(H5F_t *f, haddr_t addr, void *_lt_key, * Modifications: * Robb Matzke, 1999-07-28 * The ADDR argument is passed by value. + * + * Quincey Koziol, 2002-04-22 + * Changed to callback from H5B_iterate *------------------------------------------------------------------------- */ static herr_t -H5F_istore_iterate (H5F_t UNUSED *f, void *_lt_key, haddr_t UNUSED addr, +H5F_istore_iter_dump (H5F_t UNUSED *f, void *_lt_key, haddr_t UNUSED addr, void UNUSED *_rt_key, void *_udata) { H5F_istore_ud1_t *bt_udata = (H5F_istore_ud1_t *)_udata; @@ -885,9 +918,8 @@ H5F_istore_iterate (H5F_t UNUSED *f, void *_lt_key, haddr_t UNUSED addr, HDfputs("]\n", bt_udata->stream); } - bt_udata->total_storage += lt_key->nbytes; FUNC_LEAVE(SUCCEED); -} +} /* H5F_istore_iter_dump() */ /*------------------------------------------------------------------------- @@ -2148,7 +2180,7 @@ H5F_istore_allocated(H5F_t *f, unsigned ndims, haddr_t addr) HDmemset(&udata, 0, sizeof udata); udata.mesg.ndims = ndims; - if (H5B_iterate(f, H5B_ISTORE, addr, &udata)<0) { + if (H5B_iterate(f, H5B_ISTORE, H5F_istore_iter_allocated, addr, &udata)<0) { HRETURN_ERROR(H5E_IO, H5E_CANTINIT, 0, "unable to iterate over chunk B-tree"); } @@ -2184,7 +2216,7 @@ H5F_istore_dump_btree(H5F_t *f, FILE *stream, unsigned ndims, haddr_t addr) HDmemset(&udata, 0, sizeof udata); udata.mesg.ndims = ndims; udata.stream = stream; - if (H5B_iterate(f, H5B_ISTORE, addr, &udata)<0) { + if (H5B_iterate(f, H5B_ISTORE, H5F_istore_iter_dump, addr, &udata)<0) { HRETURN_ERROR(H5E_IO, H5E_CANTINIT, 0, "unable to iterate over chunk B-tree"); } @@ -2669,18 +2701,14 @@ H5F_istore_prune_by_extent(H5F_t *f, H5O_layout_t *layout, H5S_t * space) udata.stream = stdout; udata.mesg.addr = layout->addr; udata.mesg.ndims = layout->ndims; - for(u = 0; u < udata.mesg.ndims; u++) { + for(u = 0; u < udata.mesg.ndims; u++) udata.mesg.dim[u] = layout->dim[u]; - } + udata.dims = curr_dims; - if(H5B_prune_by_extent(f, H5B_ISTORE, layout->addr, &udata, - curr_dims) < 0) { - HRETURN_ERROR(H5E_IO, H5E_CANTINIT, 0, - "unable to iterate over B-tree"); - } + if(H5B_iterate(f, H5B_ISTORE, H5F_istore_prune_extent, layout->addr, &udata) < 0) + HRETURN_ERROR(H5E_IO, H5E_CANTINIT, 0, "unable to iterate over B-tree"); FUNC_LEAVE(SUCCEED); - } @@ -2702,51 +2730,42 @@ H5F_istore_prune_by_extent(H5F_t *f, H5O_layout_t *layout, H5S_t * space) *------------------------------------------------------------------------- */ static herr_t -H5F_istore_prune_extent(H5F_t *f, void *_lt_key, haddr_t addr, void *_udata, - hsize_t *size) +H5F_istore_prune_extent(H5F_t *f, void *_lt_key, haddr_t UNUSED addr, + void UNUSED *_rt_key, void *_udata) { H5F_istore_ud1_t *bt_udata = (H5F_istore_ud1_t *)_udata; H5F_istore_key_t *lt_key = (H5F_istore_key_t *)_lt_key; unsigned u; - int found = 0; H5F_istore_ud1_t udata; - /* The LT_KEY is the left key (the onethat describes the chunk). It points to a chunk of + /* The LT_KEY is the left key (the one that describes the chunk). It points to a chunk of * storage that contains the beginning of the logical address space represented by UDATA. */ FUNC_ENTER(H5F_istore_prune_extent, FAIL); /* Figure out what chunks are no longer in use for the specified extent and release them */ - - for(u = 0; u < bt_udata->mesg.ndims - 1; u++) { - if((hsize_t)lt_key->offset[u] > size[u]) { - found = 1; - break; - } - } - - if(found) { + for(u = 0; u < bt_udata->mesg.ndims - 1; u++) + if((hsize_t)lt_key->offset[u] > bt_udata->dims[u]) { #if defined (H5F_ISTORE_DEBUG) - HDfputs("b-tree:remove:[", bt_udata->stream); - for(u = 0; u < bt_udata->mesg.ndims - 1; u++) { - HDfprintf(bt_udata->stream, "%s%Hd", u ? ", " : "", - lt_key->offset[u]); - } - HDfputs("]\n", bt_udata->stream); + HDfputs("b-tree:remove:[", bt_udata->stream); + for(u = 0; u < bt_udata->mesg.ndims - 1; u++) { + HDfprintf(bt_udata->stream, "%s%Hd", u ? ", " : "", + lt_key->offset[u]); + } + HDfputs("]\n", bt_udata->stream); #endif - HDmemset(&udata, 0, sizeof udata); - udata.key = *lt_key; - udata.mesg = bt_udata->mesg; + HDmemset(&udata, 0, sizeof udata); + udata.key = *lt_key; + udata.mesg = bt_udata->mesg; - /* Remove */ - if(H5B_remove(f, H5B_ISTORE, addr, &udata) < 0) { - HRETURN_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, - "unable to remove entry"); - } - } + /* Remove */ + if(H5B_remove(f, H5B_ISTORE, bt_udata->mesg.addr, &udata) < 0) + HRETURN_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to remove entry"); + break; + } /* end if */ FUNC_LEAVE(SUCCEED); } diff --git a/src/H5Fistore.c b/src/H5Fistore.c index d2cb490..54b2fd2 100644 --- a/src/H5Fistore.c +++ b/src/H5Fistore.c @@ -120,7 +120,9 @@ static H5B_ins_t H5F_istore_insert(H5F_t *f, haddr_t addr, void *_lt_key, void *_udata, void *_rt_key, hbool_t *rt_key_changed, haddr_t *new_node/*out*/); -static herr_t H5F_istore_iterate(H5F_t *f, void *left_key, haddr_t addr, +static herr_t H5F_istore_iter_allocated(H5F_t *f, void *left_key, haddr_t addr, + void *right_key, void *_udata); +static herr_t H5F_istore_iter_dump(H5F_t *f, void *left_key, haddr_t addr, void *right_key, void *_udata); static herr_t H5F_istore_decode_key(H5F_t *f, H5B_t *bt, uint8_t *raw, void *_key); @@ -130,15 +132,11 @@ static herr_t H5F_istore_debug_key(FILE *stream, int indent, int fwidth, const void *key, const void *udata); static haddr_t H5F_istore_get_addr(H5F_t *f, const H5O_layout_t *layout, const hssize_t offset[]); - -static herr_t H5F_istore_prune_extent( H5F_t *f, void *left_key, haddr_t addr, - void *_udata, hsize_t *size ); -static H5B_ins_t H5F_istore_remove( H5F_t *f, haddr_t addr, - void *_lt_key /*in,out*/, - hbool_t *lt_key_changed /*out*/, - void UNUSED *_udata /*in,out*/, - void UNUSED *_rt_key /*in,out*/, - hbool_t *rt_key_changed /*out*/); +static herr_t H5F_istore_prune_extent(H5F_t *f, void *_lt_key, haddr_t addr, + void *_rt_key, void *_udata); +static H5B_ins_t H5F_istore_remove( H5F_t *f, haddr_t addr, void *_lt_key, + hbool_t *lt_key_changed, void *_udata, void *_rt_key, + hbool_t *rt_key_changed); /* * B-tree key. A key contains the minimum logical N-dimensional address and @@ -166,6 +164,7 @@ typedef struct H5F_istore_ud1_t { H5O_layout_t mesg; /*layout message */ hsize_t total_storage; /*output from iterator */ FILE *stream; /*debug output stream */ + hsize_t *dims; /*dataset dimensions */ } H5F_istore_ud1_t; /* inherits B-tree like properties from H5B */ @@ -181,11 +180,9 @@ H5B_class_t H5B_ISTORE[1] = {{ FALSE, /*follow min branch? */ FALSE, /*follow max branch? */ H5F_istore_remove, /*remove */ - H5F_istore_iterate, /*iterator */ H5F_istore_decode_key, /*decode */ H5F_istore_encode_key, /*encode */ H5F_istore_debug_key, /*debug */ - H5F_istore_prune_extent, /*remove chunks, upon H5Dset_extend call */ }}; #define H5F_HASH_DIVISOR 8 /* Attempt to spread out the hashing */ @@ -840,11 +837,44 @@ H5F_istore_insert(H5F_t *f, haddr_t addr, void *_lt_key, /*------------------------------------------------------------------------- - * Function: H5F_istore_iterate + * Function: H5F_istore_iter_allocated + * + * Purpose: Simply counts the number of chunks for a dataset. + * + * Return: Success: Non-negative + * + * Failure: Negative + * + * Programmer: Robb Matzke + * Wednesday, April 21, 1999 + * + * Modifications: + * Robb Matzke, 1999-07-28 + * The ADDR argument is passed by value. + * + * Quincey Koziol, 2002-04-22 + * Changed to callback from H5B_iterate + *------------------------------------------------------------------------- + */ +static herr_t +H5F_istore_iter_allocated (H5F_t UNUSED *f, void *_lt_key, haddr_t UNUSED addr, + void UNUSED *_rt_key, void *_udata) +{ + H5F_istore_ud1_t *bt_udata = (H5F_istore_ud1_t *)_udata; + H5F_istore_key_t *lt_key = (H5F_istore_key_t *)_lt_key; + + FUNC_ENTER(H5F_istore_iterate, FAIL); + + bt_udata->total_storage += lt_key->nbytes; + FUNC_LEAVE(SUCCEED); +} /* H5F_istore_iter_allocated() */ + + +/*------------------------------------------------------------------------- + * Function: H5F_istore_iter_dump * - * Purpose: Simply counts the number of chunks for a dataset. If the - * UDATA.STREAM member is non-null then debugging information is - * written to that stream. + * Purpose: If the UDATA.STREAM member is non-null then debugging + * information is written to that stream. * * Return: Success: Non-negative * @@ -856,10 +886,13 @@ H5F_istore_insert(H5F_t *f, haddr_t addr, void *_lt_key, * Modifications: * Robb Matzke, 1999-07-28 * The ADDR argument is passed by value. + * + * Quincey Koziol, 2002-04-22 + * Changed to callback from H5B_iterate *------------------------------------------------------------------------- */ static herr_t -H5F_istore_iterate (H5F_t UNUSED *f, void *_lt_key, haddr_t UNUSED addr, +H5F_istore_iter_dump (H5F_t UNUSED *f, void *_lt_key, haddr_t UNUSED addr, void UNUSED *_rt_key, void *_udata) { H5F_istore_ud1_t *bt_udata = (H5F_istore_ud1_t *)_udata; @@ -885,9 +918,8 @@ H5F_istore_iterate (H5F_t UNUSED *f, void *_lt_key, haddr_t UNUSED addr, HDfputs("]\n", bt_udata->stream); } - bt_udata->total_storage += lt_key->nbytes; FUNC_LEAVE(SUCCEED); -} +} /* H5F_istore_iter_dump() */ /*------------------------------------------------------------------------- @@ -2148,7 +2180,7 @@ H5F_istore_allocated(H5F_t *f, unsigned ndims, haddr_t addr) HDmemset(&udata, 0, sizeof udata); udata.mesg.ndims = ndims; - if (H5B_iterate(f, H5B_ISTORE, addr, &udata)<0) { + if (H5B_iterate(f, H5B_ISTORE, H5F_istore_iter_allocated, addr, &udata)<0) { HRETURN_ERROR(H5E_IO, H5E_CANTINIT, 0, "unable to iterate over chunk B-tree"); } @@ -2184,7 +2216,7 @@ H5F_istore_dump_btree(H5F_t *f, FILE *stream, unsigned ndims, haddr_t addr) HDmemset(&udata, 0, sizeof udata); udata.mesg.ndims = ndims; udata.stream = stream; - if (H5B_iterate(f, H5B_ISTORE, addr, &udata)<0) { + if (H5B_iterate(f, H5B_ISTORE, H5F_istore_iter_dump, addr, &udata)<0) { HRETURN_ERROR(H5E_IO, H5E_CANTINIT, 0, "unable to iterate over chunk B-tree"); } @@ -2669,18 +2701,14 @@ H5F_istore_prune_by_extent(H5F_t *f, H5O_layout_t *layout, H5S_t * space) udata.stream = stdout; udata.mesg.addr = layout->addr; udata.mesg.ndims = layout->ndims; - for(u = 0; u < udata.mesg.ndims; u++) { + for(u = 0; u < udata.mesg.ndims; u++) udata.mesg.dim[u] = layout->dim[u]; - } + udata.dims = curr_dims; - if(H5B_prune_by_extent(f, H5B_ISTORE, layout->addr, &udata, - curr_dims) < 0) { - HRETURN_ERROR(H5E_IO, H5E_CANTINIT, 0, - "unable to iterate over B-tree"); - } + if(H5B_iterate(f, H5B_ISTORE, H5F_istore_prune_extent, layout->addr, &udata) < 0) + HRETURN_ERROR(H5E_IO, H5E_CANTINIT, 0, "unable to iterate over B-tree"); FUNC_LEAVE(SUCCEED); - } @@ -2702,51 +2730,42 @@ H5F_istore_prune_by_extent(H5F_t *f, H5O_layout_t *layout, H5S_t * space) *------------------------------------------------------------------------- */ static herr_t -H5F_istore_prune_extent(H5F_t *f, void *_lt_key, haddr_t addr, void *_udata, - hsize_t *size) +H5F_istore_prune_extent(H5F_t *f, void *_lt_key, haddr_t UNUSED addr, + void UNUSED *_rt_key, void *_udata) { H5F_istore_ud1_t *bt_udata = (H5F_istore_ud1_t *)_udata; H5F_istore_key_t *lt_key = (H5F_istore_key_t *)_lt_key; unsigned u; - int found = 0; H5F_istore_ud1_t udata; - /* The LT_KEY is the left key (the onethat describes the chunk). It points to a chunk of + /* The LT_KEY is the left key (the one that describes the chunk). It points to a chunk of * storage that contains the beginning of the logical address space represented by UDATA. */ FUNC_ENTER(H5F_istore_prune_extent, FAIL); /* Figure out what chunks are no longer in use for the specified extent and release them */ - - for(u = 0; u < bt_udata->mesg.ndims - 1; u++) { - if((hsize_t)lt_key->offset[u] > size[u]) { - found = 1; - break; - } - } - - if(found) { + for(u = 0; u < bt_udata->mesg.ndims - 1; u++) + if((hsize_t)lt_key->offset[u] > bt_udata->dims[u]) { #if defined (H5F_ISTORE_DEBUG) - HDfputs("b-tree:remove:[", bt_udata->stream); - for(u = 0; u < bt_udata->mesg.ndims - 1; u++) { - HDfprintf(bt_udata->stream, "%s%Hd", u ? ", " : "", - lt_key->offset[u]); - } - HDfputs("]\n", bt_udata->stream); + HDfputs("b-tree:remove:[", bt_udata->stream); + for(u = 0; u < bt_udata->mesg.ndims - 1; u++) { + HDfprintf(bt_udata->stream, "%s%Hd", u ? ", " : "", + lt_key->offset[u]); + } + HDfputs("]\n", bt_udata->stream); #endif - HDmemset(&udata, 0, sizeof udata); - udata.key = *lt_key; - udata.mesg = bt_udata->mesg; + HDmemset(&udata, 0, sizeof udata); + udata.key = *lt_key; + udata.mesg = bt_udata->mesg; - /* Remove */ - if(H5B_remove(f, H5B_ISTORE, addr, &udata) < 0) { - HRETURN_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, - "unable to remove entry"); - } - } + /* Remove */ + if(H5B_remove(f, H5B_ISTORE, bt_udata->mesg.addr, &udata) < 0) + HRETURN_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to remove entry"); + break; + } /* end if */ FUNC_LEAVE(SUCCEED); } diff --git a/src/H5G.c b/src/H5G.c index 21974ef..f110800 100644 --- a/src/H5G.c +++ b/src/H5G.c @@ -330,7 +330,7 @@ H5Giterate(hid_t loc_id, const char *name, int *idx, /* Iterate over the group members */ if ((ret_value = H5B_iterate (H5G_fileof(udata.group), H5B_SNODE, - udata.group->ent.cache.stab.btree_addr, &udata))<0) { + H5G_node_iterate, udata.group->ent.cache.stab.btree_addr, &udata))<0) { HERROR (H5E_SYM, H5E_CANTINIT, "iteration operator failed"); } diff --git a/src/H5Gnode.c b/src/H5Gnode.c index d4b3df2..d830a6b 100644 --- a/src/H5Gnode.c +++ b/src/H5Gnode.c @@ -66,8 +66,6 @@ static H5B_ins_t H5G_node_insert(H5F_t *f, haddr_t addr, void *_lt_key, static H5B_ins_t H5G_node_remove(H5F_t *f, haddr_t addr, void *lt_key, hbool_t *lt_key_changed, void *udata, void *rt_key, hbool_t *rt_key_changed); -static herr_t H5G_node_iterate(H5F_t *f, void *_lt_key, haddr_t addr, - void *_rt_key, void *_udata); static size_t H5G_node_sizeof_rkey(H5F_t *f, const void *_udata); /* H5G inherits cache-like properties from H5AC */ @@ -90,11 +88,9 @@ H5B_class_t H5B_SNODE[1] = {{ TRUE, /*follow min branch? */ TRUE, /*follow max branch? */ H5G_node_remove, /*remove */ - H5G_node_iterate, /*list */ H5G_node_decode_key, /*decode */ H5G_node_encode_key, /*encode */ NULL, /*debug key */ - NULL, /*remove chunks, upon H5Dset_extend call */ }}; /* Interface initialization */ @@ -1058,9 +1054,12 @@ H5G_node_remove(H5F_t *f, haddr_t addr, void *_lt_key/*in,out*/, * Modifications: * Robb Matzke, 1999-07-28 * The ADDR argument is passed by value. + * + * Quincey Koziol, 2002-04-22 + * Changed to callback from H5B_iterate *------------------------------------------------------------------------- */ -static herr_t +herr_t H5G_node_iterate (H5F_t *f, void UNUSED *_lt_key, haddr_t addr, void UNUSED *_rt_key, void *_udata) { diff --git a/src/H5Gpkg.h b/src/H5Gpkg.h index 43409ba..c861188 100644 --- a/src/H5Gpkg.h +++ b/src/H5Gpkg.h @@ -138,6 +138,9 @@ __DLL__ herr_t H5G_ent_decode_vec(H5F_t *f, const uint8_t **pp, __DLL__ herr_t H5G_ent_encode_vec(H5F_t *f, uint8_t **pp, const H5G_entry_t *ent, int n); +/* Functions that understand symbol table nodes */ __DLL__ unsigned H5G_node_k(const H5F_t *f); +__DLL__ herr_t H5G_node_iterate (H5F_t *f, void UNUSED *_lt_key, haddr_t addr, + void UNUSED *_rt_key, void *_udata); #endif -- cgit v0.12