summaryrefslogtreecommitdiffstats
path: root/src/H5Bcache.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5Bcache.c')
-rw-r--r--src/H5Bcache.c63
1 files changed, 43 insertions, 20 deletions
diff --git a/src/H5Bcache.c b/src/H5Bcache.c
index 9f7444b..dc60f9d 100644
--- a/src/H5Bcache.c
+++ b/src/H5Bcache.c
@@ -37,6 +37,7 @@
#include "H5private.h" /* Generic Functions */
#include "H5Bpkg.h" /* B-link trees */
#include "H5Eprivate.h" /* Error handling */
+#include "H5MFprivate.h" /* File memory management */
/****************/
@@ -74,6 +75,7 @@ const H5AC_class_t H5AC_BT[1] = {{
(H5AC_flush_func_t)H5B_flush,
(H5AC_dest_func_t)H5B_dest,
(H5AC_clear_func_t)H5B_clear,
+ (H5AC_notify_func_t)NULL,
(H5AC_size_func_t)H5B_compute_size,
}};
@@ -111,13 +113,13 @@ H5B_serialize(const H5F_t *f, const H5B_t *bt)
HDassert(f);
HDassert(bt);
HDassert(bt->rc_shared);
- shared=(H5B_shared_t *)H5RC_GET_OBJ(bt->rc_shared);
+ shared = (H5B_shared_t *)H5RC_GET_OBJ(bt->rc_shared);
HDassert(shared);
p = shared->page;
/* magic number */
- HDmemcpy(p, H5B_MAGIC, (size_t)H5B_SIZEOF_MAGIC);
+ HDmemcpy(p, H5B_MAGIC, (size_t)H5_SIZEOF_MAGIC);
p += 4;
/* node type and level */
@@ -133,10 +135,10 @@ H5B_serialize(const H5F_t *f, const H5B_t *bt)
H5F_addr_encode(f, &p, bt->right);
/* child keys and pointers */
- native=bt->native;
- for (u = 0; u < bt->nchildren; ++u) {
+ native = bt->native;
+ for(u = 0; u < bt->nchildren; ++u) {
/* encode the key */
- if (shared->type->encode(f, bt, p, native) < 0)
+ if(shared->type->encode(f, bt, p, native) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTENCODE, FAIL, "unable to encode B-tree key")
p += shared->sizeof_rkey;
native += shared->type->sizeof_nkey;
@@ -144,9 +146,9 @@ H5B_serialize(const H5F_t *f, const H5B_t *bt)
/* encode the child address */
H5F_addr_encode(f, &p, bt->child[u]);
} /* end for */
- if(bt->nchildren>0) {
+ if(bt->nchildren > 0) {
/* Encode the final key */
- if (shared->type->encode(f, bt, p, native) < 0)
+ if(shared->type->encode(f, bt, p, native) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTENCODE, FAIL, "unable to encode B-tree key")
} /* end if */
@@ -188,21 +190,20 @@ H5B_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_type, void *udata)
HDassert(type);
HDassert(type->get_shared);
- /* Allocate the B-tree node in memory */
if(NULL == (bt = H5FL_MALLOC(H5B_t)))
- HGOTO_ERROR(H5E_BTREE, H5E_NOSPACE, NULL, "can't allocate B-tree struct")
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, NULL, "can't allocate B-tree struct")
HDmemset(&bt->cache_info, 0, sizeof(H5AC_info_t));
- if(NULL == (bt->rc_shared=(type->get_shared)(f, udata)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "can't retrieve B-tree node buffer")
+ if(NULL == (bt->rc_shared = (type->get_shared)(f, udata)))
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, NULL, "can't retrieve B-tree node buffer")
shared = (H5B_shared_t *)H5RC_GET_OBJ(bt->rc_shared);
HDassert(shared);
/* Allocate space for the native keys and child addresses */
if(NULL == (bt->native = H5FL_BLK_MALLOC(native_block, shared->sizeof_keys)))
- HGOTO_ERROR(H5E_BTREE, H5E_NOSPACE, NULL, "can't allocate buffer for native keys")
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, NULL, "can't allocate buffer for native keys")
if(NULL == (bt->child = H5FL_SEQ_MALLOC(haddr_t, (size_t)shared->two_k)))
- HGOTO_ERROR(H5E_BTREE, H5E_NOSPACE, NULL, "can't allocate buffer for child addresses")
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, NULL, "can't allocate buffer for child addresses")
if(H5F_block_read(f, H5FD_MEM_BTREE, addr, shared->sizeof_rnode, dxpl_id, shared->page) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_READERROR, NULL, "can't read B-tree node")
@@ -211,7 +212,7 @@ H5B_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_type, void *udata)
p = shared->page;
/* magic number */
- if(HDmemcmp(p, H5B_MAGIC, (size_t)H5B_SIZEOF_MAGIC))
+ if(HDmemcmp(p, H5B_MAGIC, (size_t)H5_SIZEOF_MAGIC))
HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, NULL, "wrong B-tree signature")
p += 4;
@@ -297,7 +298,7 @@ H5B_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5B_t *bt, uns
* bother writing data for the child entries that don't exist or
* for the final unchanged children.
*/
- if (H5F_block_write(f, H5FD_MEM_BTREE, addr, shared->sizeof_rnode, dxpl_id, shared->page) < 0)
+ if(H5F_block_write(f, H5FD_MEM_BTREE, addr, shared->sizeof_rnode, dxpl_id, shared->page) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTFLUSH, FAIL, "unable to save B-tree node to disk")
bt->cache_info.is_dirty = FALSE;
@@ -325,24 +326,45 @@ done:
*
*-------------------------------------------------------------------------
*/
-/* ARGSUSED */
herr_t
-H5B_dest(H5F_t UNUSED *f, H5B_t *bt)
+H5B_dest(H5F_t *f, H5B_t *bt)
{
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5B_dest)
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT(H5B_dest)
/*
* Check arguments.
*/
+ HDassert(f);
HDassert(bt);
HDassert(bt->rc_shared);
+ /* If we're going to free the space on disk, the address must be valid */
+ HDassert(!bt->cache_info.free_file_space_on_destroy || H5F_addr_defined(bt->cache_info.addr));
+
+ /* Check for freeing file space for B-tree node */
+ if(bt->cache_info.free_file_space_on_destroy) {
+ H5B_shared_t *shared; /* Pointer to shared B-tree info */
+
+ /* Get the pointer to the shared B-tree info */
+ shared = (H5B_shared_t *)H5RC_GET_OBJ(bt->rc_shared);
+ HDassert(shared);
+
+ /* Release the space on disk */
+ /* (XXX: Nasty usage of internal DXPL value! -QAK) */
+ if(H5MF_xfree(f, H5FD_MEM_BTREE, H5AC_dxpl_id, bt->cache_info.addr, (hsize_t)shared->sizeof_rnode) < 0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to free B-tree node")
+ } /* end if */
+
+ /* Release resources for B-tree node */
bt->child = H5FL_SEQ_FREE(haddr_t, bt->child);
bt->native = H5FL_BLK_FREE(native_block, bt->native);
H5RC_DEC(bt->rc_shared);
bt = H5FL_FREE(H5B_t, bt);
- FUNC_LEAVE_NOAPI(SUCCEED)
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5B_dest() */
@@ -408,7 +430,7 @@ H5B_compute_size(const H5F_t UNUSED *f, const H5B_t *bt, size_t *size_ptr)
HDassert(f);
HDassert(bt);
HDassert(bt->rc_shared);
- shared=(H5B_shared_t *)H5RC_GET_OBJ(bt->rc_shared);
+ shared = (H5B_shared_t *)H5RC_GET_OBJ(bt->rc_shared);
HDassert(shared);
HDassert(shared->type);
HDassert(size_ptr);
@@ -418,3 +440,4 @@ H5B_compute_size(const H5F_t UNUSED *f, const H5B_t *bt, size_t *size_ptr)
FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5B_compute_size() */
+