summaryrefslogtreecommitdiffstats
path: root/src/H5Fspace.c
diff options
context:
space:
mode:
authorVailin Choi <vchoi@jam.ad.hdfgroup.org>2018-09-28 16:29:02 (GMT)
committerVailin Choi <vchoi@jam.ad.hdfgroup.org>2018-09-28 16:29:02 (GMT)
commit5c7ca8afff0e635f12652c35dbe9818235ac34c4 (patch)
tree1245d78ca4b0aaeb40ecab6b2615ddad886042c3 /src/H5Fspace.c
parent06fa8a94558939400dc43e99c08a784e26dfa01d (diff)
downloadhdf5-5c7ca8afff0e635f12652c35dbe9818235ac34c4.zip
hdf5-5c7ca8afff0e635f12652c35dbe9818235ac34c4.tar.gz
hdf5-5c7ca8afff0e635f12652c35dbe9818235ac34c4.tar.bz2
Third batch of checkin:
1) Free space manager for the metadata file 2) Delayed free space release linked list 3) H5F_update_vfd_swmr_metadata_file() 3) VFD SWMR driver: read callback 4) Flushing for VFD SWMR 5) Port one concurrent test from swmr test set 6) Bug fixes and refactoring
Diffstat (limited to 'src/H5Fspace.c')
-rw-r--r--src/H5Fspace.c160
1 files changed, 160 insertions, 0 deletions
diff --git a/src/H5Fspace.c b/src/H5Fspace.c
index 6baf163..a35fdff 100644
--- a/src/H5Fspace.c
+++ b/src/H5Fspace.c
@@ -42,6 +42,10 @@
/* Local Macros */
/****************/
+/* Define this to display debugging information for VFD SWMR */
+/* #define H5F_VFD_SWMR_DEBUG */
+
+
/******************/
/* Local Typedefs */
@@ -56,6 +60,7 @@
/********************/
/* Local Prototypes */
/********************/
+static haddr_t H5F__extend_md(H5F_t *f, hsize_t size);
/*********************/
@@ -222,3 +227,158 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F__try_extend() */
+
+/*
+ * VFD SWMR
+ */
+
+/*-------------------------------------------------------------------------
+ * Function: H5F__free_md
+ *
+ * Purpose: Release space at the end of the metadata file's allocated space
+ *
+ * Return: Success: Non-negative
+ * Failure: Negative
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5F__free_md(H5F_t *f, haddr_t addr, hsize_t size)
+{
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_PACKAGE
+
+ /* Check args */
+ HDassert(f);
+ HDassert(f->shared);
+ HDassert(size > 0);
+
+ /* Sanity checking */
+ if(!H5F_addr_defined(addr))
+ HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "invalid file offset")
+
+ if(addr > f->shared->maxaddr || H5F_addr_overflow(addr, size) || (addr + size) > f->shared->maxaddr)
+ HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "invalid file free space region to free")
+
+ /* Check if this free block is at the end of file allocated space.
+ * Truncate it if this is true.
+ */
+ if(f->shared->vfd_swmr_md_eoa == (addr + size))
+ f->shared->vfd_swmr_md_eoa = addr;
+ else {
+ /* leak memory */
+#ifdef H5F_VFD_SWMR_DEBUG
+HDfprintf(stderr, "%s: LEAKED MEMORY!!! addr = %a, size = %Hu\n", FUNC, addr, size);
+#endif
+ } /* end else */
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5F__free_md() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5F__alloc_md
+ *
+ * Purpose: Allocate space at the end of the metadata file
+ *
+ * Return: Success: Non-negative
+ * Failure: Negative
+ *
+ *-------------------------------------------------------------------------
+ */
+haddr_t
+H5F__alloc_md(H5F_t *f, hsize_t size)
+{
+ haddr_t ret_value = HADDR_UNDEF; /* Return value */
+
+ FUNC_ENTER_PACKAGE
+
+ /* check args */
+ HDassert(f);
+ HDassert(f->shared);
+ HDassert(size > 0);
+
+ /* Extend the EOA space of the metadata file */
+ ret_value = H5F__extend_md(f, size);
+
+ if(!H5F_addr_defined(ret_value))
+ HGOTO_ERROR(H5E_VFL, H5E_NOSPACE, HADDR_UNDEF, "driver eoa update request failed")
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+
+} /* end H5F__alloc_md() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5F__try_extend_md
+ *
+ * Purpose: Try to extend a block at the end of the metadata file, if possible.
+ *
+ * Return: Success: Non-negative
+ * Failure: Negative
+ *
+ *-------------------------------------------------------------------------
+ */
+htri_t
+H5F__try_extend_md(H5F_t *f, haddr_t blk_end, hsize_t extra_requested)
+{
+ htri_t ret_value = FALSE; /* Return value */
+
+ FUNC_ENTER_PACKAGE
+
+ /* check args */
+ HDassert(f);
+ HDassert(f->shared);
+ HDassert(extra_requested > 0);
+
+ /* Check if the block is exactly at the end of the file */
+ if(H5F_addr_eq(blk_end, f->shared->vfd_swmr_md_eoa)) {
+
+ /* Extend the EOA space of the metadata file */
+ if(HADDR_UNDEF == H5F__extend_md(f, extra_requested))
+ HGOTO_ERROR(H5E_FILE, H5E_CANTEXTEND, FAIL, "driver extend request failed")
+
+ /* Indicate success */
+ ret_value = TRUE;
+ }
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5F__try_extend_md() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5F__extend_md
+ *
+ * Purpose: Extend the EOA space of the metadata file.
+ *
+ * Return: Success: Non-negative
+ * Failure: Negative
+ *
+ *-------------------------------------------------------------------------
+ */
+static haddr_t
+H5F__extend_md(H5F_t *f, hsize_t size)
+{
+ haddr_t eoa;
+ haddr_t ret_value = HADDR_UNDEF; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT
+
+ /* Get current end-of-allocated space address */
+ eoa = f->shared->vfd_swmr_md_eoa;
+
+ /* Check for overflow when extending */
+ if(H5F_addr_overflow(eoa, size) || (eoa + size) > f->shared->maxaddr)
+ HGOTO_ERROR(H5E_FILE, H5E_NOSPACE, HADDR_UNDEF, "file allocation request failed")
+
+ /* Set the address to return */
+ ret_value = eoa;
+
+ /* Extend the end-of-allocated space address */
+ f->shared->vfd_swmr_md_eoa += size;
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+}