summaryrefslogtreecommitdiffstats
path: root/src/H5FDmulti.c
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2015-12-14 10:03:54 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2015-12-14 10:03:54 (GMT)
commit7e4fb729137dff3851122be63beabfc03137be4a (patch)
tree490996cc619adf8cd059e2df66aba441d51bc09f /src/H5FDmulti.c
parentf6c7631b3c40e03abe228cf9b3c2308c610d04cd (diff)
downloadhdf5-7e4fb729137dff3851122be63beabfc03137be4a.zip
hdf5-7e4fb729137dff3851122be63beabfc03137be4a.tar.gz
hdf5-7e4fb729137dff3851122be63beabfc03137be4a.tar.bz2
[svn-r28626] Brought VFD-level file locking code over from revise_chunks.
Tested on: Ubuntu 15.10 (Linux 4.2.0 x86_64) gcc 5.2.1 serial only (these changes have been in revise_chunks for a long time)
Diffstat (limited to 'src/H5FDmulti.c')
-rw-r--r--src/H5FDmulti.c101
1 files changed, 99 insertions, 2 deletions
diff --git a/src/H5FDmulti.c b/src/H5FDmulti.c
index 92df2ad..181ad39 100644
--- a/src/H5FDmulti.c
+++ b/src/H5FDmulti.c
@@ -135,6 +135,8 @@ static herr_t H5FD_multi_write(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, ha
size_t size, const void *_buf);
static herr_t H5FD_multi_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing);
static herr_t H5FD_multi_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing);
+static herr_t H5FD_multi_lock(H5FD_t *_file, hbool_t rw);
+static herr_t H5FD_multi_unlock(H5FD_t *_file);
/* The class struct */
static const H5FD_class_t H5FD_multi_g = {
@@ -167,8 +169,8 @@ static const H5FD_class_t H5FD_multi_g = {
H5FD_multi_write, /*write */
H5FD_multi_flush, /*flush */
H5FD_multi_truncate, /*truncate */
- NULL, /*lock */
- NULL, /*unlock */
+ H5FD_multi_lock, /*lock */
+ H5FD_multi_unlock, /*unlock */
H5FD_FLMAP_DEFAULT /*fl_map */
};
@@ -1786,6 +1788,101 @@ H5FD_multi_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing)
/*-------------------------------------------------------------------------
+ * Function: H5FD_multi_lock
+ *
+ * Purpose: Place a lock on all multi members.
+ * When there is error in locking a member file, it will not
+ * proceed further and will try to remove the locks of those
+ * member files that are locked before error is encountered.
+ *
+ * Return: Success: 0
+ * Failure: -1
+ *
+ * Programmer: Vailin Choi; March 2015
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5FD_multi_lock(H5FD_t *_file, hbool_t rw)
+{
+ H5FD_multi_t *file = (H5FD_multi_t*)_file;
+ int nerrors = 0;
+ H5FD_mem_t out_mt;
+ static const char *func="H5FD_multi_unlock"; /* Function Name for error reporting */
+
+ /* Clear the error stack */
+ H5Eclear2(H5E_DEFAULT);
+
+ /* Lock all member files */
+ ALL_MEMBERS(mt) {
+ out_mt = mt;
+ if(file->memb[mt]) {
+ H5E_BEGIN_TRY {
+ if(H5FDlock(file->memb[mt], rw) < 0) {
+ nerrors++;
+ break;
+ } /* end if */
+ } H5E_END_TRY;
+ } /* end if */
+ } END_MEMBERS;
+
+ /* Try to unlock the member files that are locked before error is encountered */
+ if(nerrors) {
+ H5FD_mem_t k;
+
+ for(k = H5FD_MEM_DEFAULT; k < out_mt; k = (H5FD_mem_t)(k + 1)) {
+ H5E_BEGIN_TRY {
+ if(H5FDunlock(file->memb[k]) < 0)
+ nerrors++;
+ } H5E_END_TRY;
+ } /* end for */
+ } /* end if */
+
+ if(nerrors)
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "error locking member files", -1)
+ return 0;
+
+} /* H5FD_multi_lock() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5FD_multi_unlock
+ *
+ * Purpose: Remove the lock on all multi members.
+ * It will try to unlock all member files but will record error
+ * encountered.
+ *
+ * Return: Success: 0
+ * Failure: -1
+ *
+ * Programmer: Vailin Choi; March 2015
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5FD_multi_unlock(H5FD_t *_file)
+{
+ H5FD_multi_t *file = (H5FD_multi_t*)_file;
+ int nerrors=0;
+ static const char *func="H5FD_multi_unlock"; /* Function Name for error reporting */
+
+ /* Clear the error stack */
+ H5Eclear2(H5E_DEFAULT);
+
+ ALL_MEMBERS(mt) {
+ if(file->memb[mt])
+ if(H5FDunlock(file->memb[mt]) < 0)
+ nerrors++;
+ } END_MEMBERS;
+
+ if(nerrors)
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "error unlocking member files", -1)
+
+ return 0;
+} /* H5FD_multi_unlock() */
+
+
+/*-------------------------------------------------------------------------
* Function: compute_next
*
* Purpose: Compute the memb_next[] values of the file based on the