summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2020-08-17 23:02:34 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2020-08-17 23:02:34 (GMT)
commit433078bc80c9516fb0d79b3602ff1fe66d28c04c (patch)
tree490bf669896e2b07c5a5094063f87ab2be2b0914
parent5d8c5849e5a3fe2b6a1e7c7d218da301edcc8f09 (diff)
parentf02ced7e7443563581930a6c2d58d1628608bbdd (diff)
downloadhdf5-433078bc80c9516fb0d79b3602ff1fe66d28c04c.zip
hdf5-433078bc80c9516fb0d79b3602ff1fe66d28c04c.tar.gz
hdf5-433078bc80c9516fb0d79b3602ff1fe66d28c04c.tar.bz2
Merge pull request #2794 in HDFFV/hdf5 from ~DEROBINS/hdf5_der:h5f_start_swmr_write_locks_dev2 to develop
* commit 'f02ced7e7443563581930a6c2d58d1628608bbdd': Moves lock flag to H5F_shared_t and adds test. Adds fix for H5Fstart_swmr_write lock issue
-rw-r--r--src/H5Fint.c24
-rw-r--r--src/H5Fpkg.h1
-rw-r--r--src/H5Fprivate.h3
-rw-r--r--src/H5Fquery.c21
-rw-r--r--test/swmr.c90
5 files changed, 127 insertions, 12 deletions
diff --git a/src/H5Fint.c b/src/H5Fint.c
index 46508fe..7e3876f 100644
--- a/src/H5Fint.c
+++ b/src/H5Fint.c
@@ -1885,6 +1885,15 @@ H5F_open(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id)
shared = file->shared;
lf = shared->lf;
+ /* Set the file locking flag. If the file is already open, the file
+ * requested file locking flag must match that of the open file.
+ */
+ if(shared->nrefs == 1)
+ file->shared->use_file_locking = use_file_locking;
+ else if(shared->nrefs > 1)
+ if(file->shared->use_file_locking != use_file_locking)
+ HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "file locking flag values don't match")
+
/* Check if page buffering is enabled */
if(H5P_get(a_plist, H5F_ACS_PAGE_BUFFER_SIZE_NAME, &page_buf_size) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTGET, NULL, "can't get page buffer size")
@@ -3695,6 +3704,12 @@ H5F__start_swmr_write(H5F_t *f)
setup = TRUE;
+ /* Place an advisory lock on the file */
+ if(H5F_USE_FILE_LOCKING(f))
+ if(H5FD_lock(f->shared->lf, TRUE) < 0) {
+ HGOTO_ERROR(H5E_FILE, H5E_CANTLOCKFILE, FAIL, "unable to lock the file")
+ }
+
/* Mark superblock as dirty */
if(H5F_super_dirty(f) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTMARKDIRTY, FAIL, "unable to mark superblock as dirty")
@@ -3712,10 +3727,6 @@ H5F__start_swmr_write(H5F_t *f)
if(H5O_refresh_metadata_reopen(obj_ids[u], &obj_glocs[u], vol_connector, TRUE) < 0)
HGOTO_ERROR(H5E_ATOM, H5E_CLOSEERROR, FAIL, "can't refresh-close object")
- /* Unlock the file */
- if(H5FD_unlock(f->shared->lf) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to unlock the file")
-
done:
if(ret_value < 0 && setup) {
@@ -3744,6 +3755,11 @@ done:
HDONE_ERROR(H5E_FILE, H5E_CANTFLUSH, FAIL, "unable to flush superblock")
} /* end if */
+ /* Unlock the file */
+ if(H5F_USE_FILE_LOCKING(f))
+ if(H5FD_unlock(f->shared->lf) < 0)
+ HDONE_ERROR(H5E_FILE, H5E_CANTUNLOCKFILE, FAIL, "unable to unlock the file")
+
/* Free memory */
if(obj_ids)
H5MM_xfree(obj_ids);
diff --git a/src/H5Fpkg.h b/src/H5Fpkg.h
index ff44536..30306d8 100644
--- a/src/H5Fpkg.h
+++ b/src/H5Fpkg.h
@@ -306,6 +306,7 @@ struct H5F_shared_t {
struct H5G_t *root_grp; /* Open root group */
H5FO_t *open_objs; /* Open objects in file */
H5UC_t *grp_btree_shared; /* Ref-counted group B-tree node info */
+ hbool_t use_file_locking; /* Whether or not to use file locking */
hbool_t closing; /* File is in the process of being closed */
/* Cached VOL connector ID & info */
diff --git a/src/H5Fprivate.h b/src/H5Fprivate.h
index 384a781..552855b 100644
--- a/src/H5Fprivate.h
+++ b/src/H5Fprivate.h
@@ -338,6 +338,7 @@ typedef struct H5F_t H5F_t;
#define H5F_SET_MIN_DSET_OHDR(F, V) ((F)->shared->crt_dset_min_ohdr_flag = (V))
#define H5F_VOL_CLS(F) ((F)->shared->vol_cls)
#define H5F_VOL_OBJ(F) ((F)->vol_obj)
+#define H5F_USE_FILE_LOCKING(F) ((F)->shared->use_file_locking)
#else /* H5F_MODULE */
#define H5F_LOW_BOUND(F) (H5F_get_low_bound(F))
#define H5F_HIGH_BOUND(F) (H5F_get_high_bound(F))
@@ -400,6 +401,7 @@ typedef struct H5F_t H5F_t;
#define H5F_SET_MIN_DSET_OHDR(F, V) (H5F_set_min_dset_ohdr((F), (V)))
#define H5F_VOL_CLS(F) (H5F_get_vol_cls(F))
#define H5F_VOL_OBJ(F) (H5F_get_vol_obj(F))
+#define H5F_USE_FILE_LOCKING(F) (H5F_get_use_file_locking(F))
#endif /* H5F_MODULE */
@@ -765,6 +767,7 @@ H5_DLL hbool_t H5F_get_min_dset_ohdr(const H5F_t *f);
H5_DLL herr_t H5F_set_min_dset_ohdr(H5F_t *f, hbool_t minimize);
H5_DLL const H5VL_class_t *H5F_get_vol_cls(const H5F_t *f);
H5_DLL H5VL_object_t *H5F_get_vol_obj(const H5F_t *f);
+H5_DLL hbool_t H5F_get_file_locking(const H5F_t *f);
/* Functions than retrieve values set/cached from the superblock/FCPL */
H5_DLL haddr_t H5F_get_base_addr(const H5F_t *f);
diff --git a/src/H5Fquery.c b/src/H5Fquery.c
index 565f492..51f2194 100644
--- a/src/H5Fquery.c
+++ b/src/H5Fquery.c
@@ -1363,3 +1363,24 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F_get_cont_info */
+
+/*-------------------------------------------------------------------------
+ * Function: H5F_get_file_locking
+ *
+ * Purpose: Get the file locking flag for the file
+ *
+ * Return: TRUE/FALSE
+ *
+ *-------------------------------------------------------------------------
+ */
+hbool_t
+H5F_get_file_locking(const H5F_t *f)
+{
+ FUNC_ENTER_NOAPI_NOINIT_NOERR
+
+ HDassert(f);
+ HDassert(f->shared);
+
+ FUNC_LEAVE_NOAPI(f->shared->use_file_locking)
+} /* end H5F_get_file_locking */
+
diff --git a/test/swmr.c b/test/swmr.c
index a839a74..67fb41b 100644
--- a/test/swmr.c
+++ b/test/swmr.c
@@ -6057,16 +6057,13 @@ error:
} /* end test_file_lock_swmr_concur() */
-
-
#endif /* !(defined(H5_HAVE_FORK && defined(H5_HAVE_WAITPID)) */
/****************************************************************
**
-** test_file_lock_swmr_concur(): low-level file test routine.
-** With the implementation of file locking, this test checks file
-** open with different combinations of flags + SWMR flags.
-** This is for concurrent access.
+** test_file_locking():
+** Tests various combinations of file locking flags and
+** and environment variables.
**
*****************************************************************/
static int
@@ -6244,6 +6241,79 @@ error:
} /* end test_file_locking() */
+/****************************************************************
+**
+** test_different_lock_flags():
+** Tests opening a file multiple times with different lock
+** flags.
+**
+*****************************************************************/
+static int
+test_different_lock_flags(hid_t in_fapl)
+{
+ hid_t fid1 = H5I_INVALID_HID; /* File ID */
+ hid_t fid2 = H5I_INVALID_HID; /* File ID */
+ hid_t fid3 = H5I_INVALID_HID; /* File ID */
+ hid_t fapl_id = H5I_INVALID_HID; /* File access property list */
+ char filename[NAME_BUF_SIZE]; /* File name */
+
+ TESTING("Using different lock flags")
+
+ /* Copy the incoming fapl */
+ if((fapl_id = H5Pcopy(in_fapl)) < 0)
+ TEST_ERROR
+
+ /* Set locking in the fapl */
+ if(H5Pset_file_locking(fapl_id, TRUE, TRUE) < 0)
+ TEST_ERROR
+
+ /* Set the filename to use for this test (dependent on fapl) */
+ h5_fixname(FILENAME[1], fapl_id, filename, sizeof(filename));
+
+ /* Create the test file */
+ if((fid1 = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id)) < 0)
+ TEST_ERROR
+
+ /* Open the test file with the same flags (should pass) */
+ if((fid2 = H5Fopen(filename, H5F_ACC_RDWR, fapl_id)) < 0)
+ TEST_ERROR
+
+ /* Unset locking in the fapl */
+ if(H5Pset_file_locking(fapl_id, FALSE, FALSE) < 0)
+ TEST_ERROR
+
+ /* Open the test file with different flags (should FAIL) */
+ H5E_BEGIN_TRY {
+ fid3 = H5Fopen(filename, H5F_ACC_RDWR, fapl_id);
+ } H5E_END_TRY;
+ if(H5I_INVALID_HID != fid3)
+ FAIL_PUTS_ERROR("Should not have been able to open a file with different locking flags")
+
+ /* Close the files */
+ if(H5Fclose(fid1) < 0)
+ TEST_ERROR
+ if(H5Fclose(fid2) < 0)
+ TEST_ERROR
+
+ /* Close the copied property list */
+ if(H5Pclose(fapl_id) < 0)
+ TEST_ERROR
+
+ PASSED();
+
+ return 0;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Pclose(fapl_id);
+ H5Fclose(fid1);
+ H5Fclose(fid2);
+ H5Fclose(fid3);
+ } H5E_END_TRY;
+
+ return -1;
+} /* end test_different_lock_flags() */
+
static int
test_swmr_vfd_flag(void)
{
@@ -7181,8 +7251,12 @@ main(void)
if(NULL == driver || !HDstrcmp(driver, "") || !HDstrcmp(driver, "sec2"))
nerrors += test_swmr_vfd_flag();
- /* This test changes the HDF5_USE_FILE_LOCKING environment variable
- * so it should be run last.
+ /* Test multiple opens via different locking flags */
+ if (use_file_locking && file_locking_enabled)
+ nerrors += test_different_lock_flags(fapl);
+
+ /* These tests change the HDF5_USE_FILE_LOCKING environment variable
+ * so they should be run last.
*/
if (use_file_locking && file_locking_enabled) {
nerrors += test_file_locking(fapl, TRUE, TRUE);