diff options
Diffstat (limited to 'src/H5FDcore.c')
-rw-r--r-- | src/H5FDcore.c | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/src/H5FDcore.c b/src/H5FDcore.c index f29e231..9090679 100644 --- a/src/H5FDcore.c +++ b/src/H5FDcore.c @@ -1479,23 +1479,31 @@ done: static herr_t H5FD_core_lock(H5FD_t *_file, hbool_t rw) { - H5FD_core_t *file = (H5FD_core_t*)_file; /* VFD file struct */ - int lock; /* The type of lock */ - herr_t ret_value = SUCCEED; /* Return value */ + H5FD_core_t *file = (H5FD_core_t*)_file; /* VFD file struct */ + int lock_flags; /* file locking flags */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT HDassert(file); + + /* Only set the lock if there is a file descriptor. If no file + * descriptor, this is a no-op. + */ if(file->fd >= 0) { - /* Determine the type of lock */ - lock = rw ? LOCK_EX : LOCK_SH; - - /* Place the lock with non-blocking */ - if(HDflock(file->fd, lock | LOCK_NB) < 0) - HSYS_GOTO_ERROR(H5E_FILE, H5E_BADFILE, FAIL, "unable to flock file") - } - /* Otherwise a noop */ + /* 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)") + else + HSYS_GOTO_ERROR(H5E_FILE, H5E_BADFILE, FAIL, "unable to lock file") + } /* end if */ + + } /* end if */ done: FUNC_LEAVE_NOAPI(ret_value) @@ -1525,11 +1533,16 @@ H5FD_core_unlock(H5FD_t *_file) if(file->fd >= 0) { - if(HDflock(file->fd, LOCK_UN) < 0) - HSYS_GOTO_ERROR(H5E_FILE, H5E_BADFILE, FAIL, "unable to flock (unlock) file") - } - /* Otherwise a noop */ + 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)") + else + HSYS_GOTO_ERROR(H5E_FILE, H5E_BADFILE, FAIL, "unable to unlock file") + } /* end if */ + + } /* end if */ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5FD_core_unlock() */ + |