summaryrefslogtreecommitdiffstats
path: root/test/h5test.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@lbl.gov>2020-08-07 15:06:34 (GMT)
committerQuincey Koziol <koziol@lbl.gov>2020-08-07 15:06:34 (GMT)
commita2340cec3b1ff84e991b4e8d54a5e358a38831fe (patch)
treebb49b22a1ea2e6edf8a379c4e13438d170937696 /test/h5test.c
parent8fe3cece3c671453e4c49f22fde9d7635c08f031 (diff)
parent51ab52ad4298913d18d1f8c3be7e2c2a410c58a8 (diff)
downloadhdf5-a2340cec3b1ff84e991b4e8d54a5e358a38831fe.zip
hdf5-a2340cec3b1ff84e991b4e8d54a5e358a38831fe.tar.gz
hdf5-a2340cec3b1ff84e991b4e8d54a5e358a38831fe.tar.bz2
Merge remote-tracking branch 'origin/develop' into namespace_cleanup_01
Diffstat (limited to 'test/h5test.c')
-rw-r--r--test/h5test.c60
1 files changed, 59 insertions, 1 deletions
diff --git a/test/h5test.c b/test/h5test.c
index 28513b9..255932a 100644
--- a/test/h5test.c
+++ b/test/h5test.c
@@ -12,7 +12,7 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
- * Programmer: Robb Matzke <matzke@llnl.gov>
+ * Programmer: Robb Matzke
* Thursday, November 19, 1998
*
* Purpose: Provides support functions for most of the hdf5 tests cases.
@@ -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() */
+