summaryrefslogtreecommitdiffstats
path: root/test/h5test.c
diff options
context:
space:
mode:
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 33af30d..dbd1a90 100644
--- a/test/h5test.c
+++ b/test/h5test.c
@@ -2267,3 +2267,61 @@ done:
HDfree(dup_buf);
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 *is_enabled)
+{
+ const char *filename = "locking_test_file";
+ int pmode = O_RDWR | O_CREAT | O_TRUNC;
+ int fd = -1;
+
+ *is_enabled = TRUE;
+
+ if ((fd = HDopen(filename, pmode, H5_POSIX_CREATE_MODE_RW)) < 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;
+ *is_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:
+ *is_enabled = FALSE;
+ if (fd > -1) {
+ HDclose(fd);
+ HDremove(filename);
+ }
+ return FAIL;
+} /* end h5_check_if_file_locking_enabled() */