summaryrefslogtreecommitdiffstats
path: root/test/h5test.c
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2020-08-06 23:31:41 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2020-08-06 23:31:41 (GMT)
commit72363de1c0707687dde4326ac807d34a94d8cd04 (patch)
tree5dc81df1f2eebd3c4f59a5a080c7a1d7ea0ef422 /test/h5test.c
parent302dfeb11b4bb5d204683dbfd6824586b3863122 (diff)
parent47ad0ac7237b464e939fe54dd129a151944d9706 (diff)
downloadhdf5-72363de1c0707687dde4326ac807d34a94d8cd04.zip
hdf5-72363de1c0707687dde4326ac807d34a94d8cd04.tar.gz
hdf5-72363de1c0707687dde4326ac807d34a94d8cd04.tar.bz2
Merge pull request #2730 in HDFFV/hdf5 from ~DEROBINS/hdf5_der:file_locking_squash_2 to develop
* commit '47ad0ac7237b464e939fe54dd129a151944d9706': Renames BEST-EFFORT to BEST_EFFORT for file locking env var Updated the file locking Fortran property list wrappers and added a test. Fixed missing parens in VFDs Minor change to header comments in file locking C++ changes. Squash merge of file locking fixes
Diffstat (limited to 'test/h5test.c')
-rw-r--r--test/h5test.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/test/h5test.c b/test/h5test.c
index 28513b9..55141ea 100644
--- a/test/h5test.c
+++ b/test/h5test.c
@@ -2243,3 +2243,61 @@ done:
return ret_value;
} /* end h5_duplicate_file_by_bytes() */
+/*-------------------------------------------------------------------------
+ * Function: h5_check_if_file_locking_enabled
+ *
+ * Purpose: Checks if file locking is enabled on this file system.
+ *
+ * Return: SUCCEED/FAIL
+ * are_enabled will be FALSE if file locking is disabled on
+ * the file system of if there were errors.
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+h5_check_if_file_locking_enabled(hbool_t *are_enabled)
+{
+ const char *filename = "locking_test_file";
+ mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
+ int fd = -1;
+
+ *are_enabled = TRUE;
+
+ if((fd = HDcreat(filename, mode)) < 0)
+ goto error;
+
+ /* Test HDflock() to see if it works */
+ if(HDflock(fd, LOCK_EX | LOCK_NB) < 0) {
+ if(ENOSYS == errno) {
+ /* When errno is set to ENOSYS, the file system does not support
+ * locking, so ignore it. This is most frequently used on
+ * Lustre. If we also want to check for disabled NFS locks
+ * we'll need to check for ENOLCK, too. That isn't done by
+ * default here since that could also represent an actual
+ * error condition.
+ */
+ errno = 0;
+ *are_enabled = FALSE;
+ }
+ else
+ goto error;
+ }
+ if(HDflock(fd, LOCK_UN) < 0)
+ goto error;
+
+ if(HDclose(fd) < 0)
+ goto error;
+ if(HDremove(filename) < 0)
+ goto error;
+
+ return SUCCEED;
+
+error:
+ *are_enabled = FALSE;
+ if (fd > -1) {
+ HDclose(fd);
+ HDremove(filename);
+ }
+ return FAIL;
+} /* end h5_check_if_file_locking_enabled() */
+