summaryrefslogtreecommitdiffstats
path: root/src/H5FDstdio.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5FDstdio.c')
-rw-r--r--src/H5FDstdio.c53
1 files changed, 45 insertions, 8 deletions
diff --git a/src/H5FDstdio.c b/src/H5FDstdio.c
index 1d401c2..68b2861 100644
--- a/src/H5FDstdio.c
+++ b/src/H5FDstdio.c
@@ -52,6 +52,9 @@
/* The driver identification number, initialized at runtime */
static hid_t H5FD_STDIO_g = 0;
+/* Whether to ignore file locks when disabled (env var value) */
+static htri_t ignore_disabled_file_locks_s = -1;
+
/* The maximum number of bytes which can be written in a single I/O operation */
static size_t H5_STDIO_MAX_IO_BYTES_g = (size_t)-1;
@@ -82,6 +85,7 @@ typedef struct H5FD_stdio_t {
haddr_t eof; /* end of file; current file size */
haddr_t pos; /* current file I/O position */
unsigned write_access; /* Flag to indicate the file was opened with write access */
+ hbool_t ignore_disabled_file_locks;
H5FD_stdio_file_op op; /* last operation */
#ifndef H5_HAVE_WIN32_API
/* On most systems the combination of device and i-node number uniquely
@@ -231,11 +235,23 @@ static const H5FD_class_t H5FD_stdio_g = {
hid_t
H5FD_stdio_init(void)
{
+ char *lock_env_var = NULL; /* Environment variable pointer */
+
/* Clear the error stack */
H5Eclear2(H5E_DEFAULT);
- if (H5I_VFL!=H5Iget_type(H5FD_STDIO_g))
+ /* Check the use disabled file locks environment variable */
+ lock_env_var = getenv("HDF5_USE_FILE_LOCKING");
+ if(lock_env_var && !strcmp(lock_env_var, "BEST_EFFORT"))
+ ignore_disabled_file_locks_s = 1; /* Override: Ignore disabled locks */
+ else if(lock_env_var && (!strcmp(lock_env_var, "TRUE") || !strcmp(lock_env_var, "1")))
+ ignore_disabled_file_locks_s = 0; /* Override: Don't ignore disabled locks */
+ else
+ ignore_disabled_file_locks_s = -1; /* Environment variable not set, or not set correctly */
+
+ if (H5I_VFL != H5Iget_type(H5FD_STDIO_g))
H5FD_STDIO_g = H5FDregister(&H5FD_stdio_g);
+
return H5FD_STDIO_g;
} /* end H5FD_stdio_init() */
@@ -318,7 +334,7 @@ H5Pset_fapl_stdio(hid_t fapl_id)
*-------------------------------------------------------------------------
*/
static H5FD_t *
-H5FD_stdio_open( const char *name, unsigned flags, hid_t /*UNUSED*/ fapl_id,
+H5FD_stdio_open( const char *name, unsigned flags, hid_t fapl_id,
haddr_t maxaddr)
{
FILE *f = NULL;
@@ -396,6 +412,21 @@ H5FD_stdio_open( const char *name, unsigned flags, hid_t /*UNUSED*/ fapl_id,
file->eof = (haddr_t)x;
}
+ /* Check the file locking flags in the fapl */
+ if(ignore_disabled_file_locks_s != -1)
+ /* The environment variable was set, so use that preferentially */
+ file->ignore_disabled_file_locks = ignore_disabled_file_locks_s;
+ else {
+ hbool_t unused;
+
+ /* Use the value in the property list */
+ if(H5Pget_file_locking(fapl_id, &unused, &file->ignore_disabled_file_locks) < 0) {
+ free(file);
+ fclose(f);
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_FILE, H5E_CANTGET, "unable to get use disabled file locks property", NULL);
+ }
+ }
+
/* Get the file descriptor (needed for truncate and some Windows information) */
#ifdef H5_HAVE_WIN32_API
file->fd = _fileno(file->fp);
@@ -1104,10 +1135,13 @@ H5FD_stdio_lock(H5FD_t *_file, hbool_t rw)
/* 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)
+ if(file->ignore_disabled_file_locks && ENOSYS == errno)
+ /* When errno is set to ENOSYS, the file system does not support
+ * locking, so ignore it.
+ */
+ errno = 0;
else
- H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_FCNTL, "file lock failed", -1)
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_VFL, H5E_CANTLOCKFILE, "file lock failed", -1)
} /* end if */
/* Flush the stream */
@@ -1152,10 +1186,13 @@ H5FD_stdio_unlock(H5FD_t *_file)
/* 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)
+ if(file->ignore_disabled_file_locks && ENOSYS == errno)
+ /* When errno is set to ENOSYS, the file system does not support
+ * locking, so ignore it.
+ */
+ errno = 0;
else
- H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_FCNTL, "file unlock failed", -1)
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_VFL, H5E_CANTUNLOCKFILE, "file unlock failed", -1)
} /* end if */
#endif /* H5_HAVE_FLOCK */