summaryrefslogtreecommitdiffstats
path: root/src/H5FDcore.c
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2020-08-14 19:35:07 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2020-08-14 19:35:07 (GMT)
commit039213d919c0bcb8f01805f34b9ff6889b06158f (patch)
treeb5c2158184ccb0c9556a4d1f89931d210d9576ca /src/H5FDcore.c
parentb8b219d19d158d272cd6b1037bbc8d6e3d64fc73 (diff)
downloadhdf5-039213d919c0bcb8f01805f34b9ff6889b06158f.zip
hdf5-039213d919c0bcb8f01805f34b9ff6889b06158f.tar.gz
hdf5-039213d919c0bcb8f01805f34b9ff6889b06158f.tar.bz2
Brings file locking changes from develop
Diffstat (limited to 'src/H5FDcore.c')
-rw-r--r--src/H5FDcore.c51
1 files changed, 39 insertions, 12 deletions
diff --git a/src/H5FDcore.c b/src/H5FDcore.c
index e4a3207..40d838c 100644
--- a/src/H5FDcore.c
+++ b/src/H5FDcore.c
@@ -36,6 +36,9 @@
/* The driver identification number, initialized at runtime */
static hid_t H5FD_CORE_g = 0;
+/* Whether to ignore file locks when disabled (env var value) */
+static htri_t ignore_disabled_file_locks_s = FAIL;
+
/* The skip list node type. Represents a region in the file. */
typedef struct H5FD_core_region_t {
haddr_t start; /* Start address of the region */
@@ -55,6 +58,7 @@ typedef struct H5FD_core_t {
size_t increment; /* multiples for mem allocation */
hbool_t backing_store; /* write to file name on flush */
size_t bstore_page_size; /* backing store page size */
+ hbool_t ignore_disabled_file_locks;
int fd; /* backing store file descriptor */
/* Information for determining uniqueness of a file with a backing store */
#ifndef H5_HAVE_WIN32_API
@@ -407,9 +411,19 @@ done:
static herr_t
H5FD__init_package(void)
{
+ char *lock_env_var = NULL; /* Environment variable pointer */
herr_t ret_value = SUCCEED;
- FUNC_ENTER_NOAPI_NOINIT
+ FUNC_ENTER_STATIC
+
+ /* Check the use disabled file locks environment variable */
+ lock_env_var = HDgetenv("HDF5_USE_FILE_LOCKING");
+ if(lock_env_var && !HDstrcmp(lock_env_var, "BEST_EFFORT"))
+ ignore_disabled_file_locks_s = TRUE; /* Override: Ignore disabled locks */
+ else if(lock_env_var && (!HDstrcmp(lock_env_var, "TRUE") || !HDstrcmp(lock_env_var, "1")))
+ ignore_disabled_file_locks_s = FALSE; /* Override: Don't ignore disabled locks */
+ else
+ ignore_disabled_file_locks_s = FAIL; /* Environment variable not set, or not set correctly */
if(H5FD_core_init() < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize core VFD")
@@ -691,6 +705,16 @@ H5FD__core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr
/* Save file image callbacks */
file->fi_callbacks = file_image_info.callbacks;
+ /* Check the file locking flags in the fapl */
+ if(ignore_disabled_file_locks_s != FAIL)
+ /* The environment variable was set, so use that preferentially */
+ file->ignore_disabled_file_locks = ignore_disabled_file_locks_s;
+ else {
+ /* Use the value in the property list */
+ if(H5P_get(plist, H5F_ACS_IGNORE_DISABLED_FILE_LOCKS_NAME, &file->ignore_disabled_file_locks) < 0)
+ HGOTO_ERROR(H5E_VFL, H5E_CANTGET, NULL, "can't get ignore disabled file locks property")
+ }
+
if(fd >= 0) {
/* Retrieve information for determining uniqueness of file */
#ifdef H5_HAVE_WIN32_API
@@ -1509,18 +1533,20 @@ H5FD_core_lock(H5FD_t *_file, hbool_t rw)
* descriptor, this is a no-op.
*/
if(file->fd >= 0) {
-
/* Set exclusive or shared lock based on rw status */
lock_flags = rw ? LOCK_EX : LOCK_SH;
/* Place a non-blocking lock on the file */
if(HDflock(file->fd, lock_flags | LOCK_NB) < 0) {
- if(ENOSYS == errno)
- HSYS_GOTO_ERROR(H5E_FILE, H5E_BADFILE, FAIL, "file locking disabled on this file system (use HDF5_USE_FILE_LOCKING environment variable to override)")
+ 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
HSYS_GOTO_ERROR(H5E_FILE, H5E_BADFILE, FAIL, "unable to lock file")
} /* end if */
-
} /* end if */
done:
@@ -1549,16 +1575,17 @@ H5FD_core_unlock(H5FD_t *_file)
HDassert(file);
- if(file->fd >= 0) {
-
+ if(file->fd >= 0)
if(HDflock(file->fd, LOCK_UN) < 0) {
- if(ENOSYS == errno)
- HSYS_GOTO_ERROR(H5E_FILE, H5E_BADFILE, FAIL, "file locking disabled on this file system (use HDF5_USE_FILE_LOCKING environment variable to override)")
+ 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
HSYS_GOTO_ERROR(H5E_FILE, H5E_BADFILE, FAIL, "unable to unlock file")
- } /* end if */
-
- } /* end if */
+ }
done:
FUNC_LEAVE_NOAPI(ret_value)