summaryrefslogtreecommitdiffstats
path: root/src/H5FDstdio.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2016-11-29 00:34:36 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2016-11-29 00:34:36 (GMT)
commitb092dbcdfdfc7477596ae49f816f18e0dadf0fb1 (patch)
treeb2ddd93f609d6449936475e41529ad021038b217 /src/H5FDstdio.c
parenta6ab26c74b29fff10e6a40bb351eb4a6eaa24162 (diff)
downloadhdf5-b092dbcdfdfc7477596ae49f816f18e0dadf0fb1.zip
hdf5-b092dbcdfdfc7477596ae49f816f18e0dadf0fb1.tar.gz
hdf5-b092dbcdfdfc7477596ae49f816f18e0dadf0fb1.tar.bz2
Bring over another batch (hopefully the last) of non-SWMR "normalization"
changes from the revise_chunks branch.
Diffstat (limited to 'src/H5FDstdio.c')
-rw-r--r--src/H5FDstdio.c49
1 files changed, 31 insertions, 18 deletions
diff --git a/src/H5FDstdio.c b/src/H5FDstdio.c
index 0168ff4..7056f7f 100644
--- a/src/H5FDstdio.c
+++ b/src/H5FDstdio.c
@@ -24,6 +24,7 @@
* and is not intended for production use!
*/
#include <assert.h>
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -1078,8 +1079,8 @@ H5FD_stdio_truncate(H5FD_t *_file, hid_t /*UNUSED*/ dxpl_id,
* Function: H5FD_stdio_lock
*
* Purpose: Lock a file via flock
- *
* NOTE: This function is a no-op if flock() is not present.
+ *
* Errors:
* IO FCNTL flock failed.
*
@@ -1093,21 +1094,27 @@ static herr_t
H5FD_stdio_lock(H5FD_t *_file, hbool_t rw)
{
#ifdef H5_HAVE_FLOCK
- H5FD_stdio_t *file = (H5FD_stdio_t*)_file;
- int lock; /* The type of lock */
- static const char *func = "H5FD_stdio_lock"; /* Function Name for error reporting */
+ H5FD_stdio_t *file = (H5FD_stdio_t*)_file; /* VFD file struct */
+ int lock_flags; /* file locking flags */
+ static const char *func = "H5FD_stdio_lock"; /* Function Name for error reporting */
/* Clear the error stack */
H5Eclear2(H5E_DEFAULT);
assert(file);
- /* Determine the type of lock */
- lock = rw ? LOCK_EX : LOCK_SH;
+ /* Set exclusive or shared lock based on rw status */
+ lock_flags = rw ? LOCK_EX : LOCK_SH;
- /* Place the lock with non-blocking */
- if(flock(file->fd, lock | LOCK_NB) < 0)
- H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_FCNTL, "flock failed", -1)
+ /* Place a non-blocking lock on the file */
+ if(flock(file->fd, lock_flags | LOCK_NB) < 0) {
+ if(ENOSYS == errno)
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_FCNTL, "file locking disabled on this file system (use HDF5_USE_FILE_LOCKING environment variable to override)", -1)
+ else
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_FCNTL, "file lock failed", -1)
+ } /* end if */
+
+ /* Flush the stream */
if(fflush(file->fp) < 0)
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_WRITEERROR, "fflush failed", -1)
@@ -1117,16 +1124,15 @@ H5FD_stdio_lock(H5FD_t *_file, hbool_t rw)
} /* end H5FD_stdio_lock() */
/*-------------------------------------------------------------------------
- * Function: H5F_stdio_unlock
- *
- * Purpose: Unlock a file via flock
+ * Function: H5F_stdio_unlock
*
+ * Purpose: Unlock a file via flock
+ * NOTE: This function is a no-op if flock() is not present.
*
- * NOTE: This function is a no-op if flock() is not present.
* Errors:
* IO FCNTL flock failed.
*
- * Return: Non-negative on success/Negative on failure
+ * Return: Non-negative on success/Negative on failure
*
* Programmer: Vailin Choi; March 2015
*
@@ -1136,18 +1142,25 @@ static herr_t
H5FD_stdio_unlock(H5FD_t *_file)
{
#ifdef H5_HAVE_FLOCK
- H5FD_stdio_t *file = (H5FD_stdio_t*)_file;
- static const char *func = "H5FD_stdio_unlock"; /* Function Name for error reporting */
+ H5FD_stdio_t *file = (H5FD_stdio_t*)_file; /* VFD file struct */
+ static const char *func = "H5FD_stdio_unlock"; /* Function Name for error reporting */
/* Clear the error stack */
H5Eclear2(H5E_DEFAULT);
assert(file);
+ /* Flush the stream */
if(fflush(file->fp) < 0)
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_WRITEERROR, "fflush failed", -1)
- if(flock(file->fd, LOCK_UN) < 0)
- H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_FCNTL, "flock (unlock) failed", -1)
+
+ /* Place a non-blocking lock on the file */
+ if(flock(file->fd, LOCK_UN) < 0) {
+ if(ENOSYS == errno)
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_FCNTL, "file locking disabled on this file system (use HDF5_USE_FILE_LOCKING environment variable to override)", -1)
+ else
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_FCNTL, "file unlock failed", -1)
+ } /* end if */
#endif /* H5_HAVE_FLOCK */