summaryrefslogtreecommitdiffstats
path: root/src/H5FDlog.c
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2015-12-14 10:03:54 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2015-12-14 10:03:54 (GMT)
commit7e4fb729137dff3851122be63beabfc03137be4a (patch)
tree490996cc619adf8cd059e2df66aba441d51bc09f /src/H5FDlog.c
parentf6c7631b3c40e03abe228cf9b3c2308c610d04cd (diff)
downloadhdf5-7e4fb729137dff3851122be63beabfc03137be4a.zip
hdf5-7e4fb729137dff3851122be63beabfc03137be4a.tar.gz
hdf5-7e4fb729137dff3851122be63beabfc03137be4a.tar.bz2
[svn-r28626] Brought VFD-level file locking code over from revise_chunks.
Tested on: Ubuntu 15.10 (Linux 4.2.0 x86_64) gcc 5.2.1 serial only (these changes have been in revise_chunks for a long time)
Diffstat (limited to 'src/H5FDlog.c')
-rw-r--r--src/H5FDlog.c81
1 files changed, 74 insertions, 7 deletions
diff --git a/src/H5FDlog.c b/src/H5FDlog.c
index eb2c0e3..a8228e0 100644
--- a/src/H5FDlog.c
+++ b/src/H5FDlog.c
@@ -179,6 +179,8 @@ static herr_t H5FD_log_read(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id, haddr
static herr_t H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id, haddr_t addr,
size_t size, const void *buf);
static herr_t H5FD_log_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing);
+static herr_t H5FD_log_lock(H5FD_t *_file, hbool_t rw);
+static herr_t H5FD_log_unlock(H5FD_t *_file);
static const H5FD_class_t H5FD_log_g = {
"log", /*name */
@@ -210,8 +212,8 @@ static const H5FD_class_t H5FD_log_g = {
H5FD_log_write, /*write */
NULL, /*flush */
H5FD_log_truncate, /*truncate */
- NULL, /*lock */
- NULL, /*unlock */
+ H5FD_log_lock, /*lock */
+ H5FD_log_unlock, /*unlock */
H5FD_FLMAP_DICHOTOMY /*fl_map */
};
@@ -888,11 +890,11 @@ H5FD_log_query(const H5FD_t *_file, unsigned long *flags /* out */)
/* Set the VFL feature flags that this driver supports */
if(flags) {
*flags = 0;
- *flags |= H5FD_FEAT_AGGREGATE_METADATA; /* OK to aggregate metadata allocations */
- *flags |= H5FD_FEAT_ACCUMULATE_METADATA; /* OK to accumulate metadata for faster writes */
- *flags |= H5FD_FEAT_DATA_SIEVE; /* OK to perform data sieving for faster raw data reads & writes */
- *flags |= H5FD_FEAT_AGGREGATE_SMALLDATA; /* OK to aggregate "small" raw data allocations */
- *flags |= H5FD_FEAT_POSIX_COMPAT_HANDLE; /* VFD handle is POSIX I/O call compatible */
+ *flags |= H5FD_FEAT_AGGREGATE_METADATA; /* OK to aggregate metadata allocations */
+ *flags |= H5FD_FEAT_ACCUMULATE_METADATA; /* OK to accumulate metadata for faster writes */
+ *flags |= H5FD_FEAT_DATA_SIEVE; /* OK to perform data sieving for faster raw data reads & writes */
+ *flags |= H5FD_FEAT_AGGREGATE_SMALLDATA; /* OK to aggregate "small" raw data allocations */
+ *flags |= H5FD_FEAT_POSIX_COMPAT_HANDLE; /* VFD handle is POSIX I/O call compatible */
/* Check for flags that are set by h5repart */
if(file && file->fam_to_sec2)
@@ -1556,3 +1558,68 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_log_truncate() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5FD_log_lock
+ *
+ * Purpose: Place a lock on the file
+ *
+ * Return: Success: SUCCEED
+ * Failure: FAIL, file not locked.
+ *
+ * Programmer: Vailin Choi; May 2013
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5FD_log_lock(H5FD_t *_file, hbool_t rw)
+{
+ H5FD_log_t *file = (H5FD_log_t *)_file;
+ int lock;
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT
+
+ /* Sanity check */
+ HDassert(file);
+
+ /* 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")
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5FD_log_lock() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5FD_log_unlock
+ *
+ * Purpose: Remove the existing lock on the file
+ *
+ * Return: SUCCEED/FAIL
+ *
+ * Programmer: Vailin Choi; May 2013
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5FD_log_unlock(H5FD_t *_file)
+{
+ H5FD_log_t *file = (H5FD_log_t *)_file; /* VFD file struct */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT
+
+ HDassert(file);
+
+ if(HDflock(file->fd, LOCK_UN) < 0)
+ HSYS_GOTO_ERROR(H5E_FILE, H5E_BADFILE, FAIL, "unable to flock (unlock) file")
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5FD_log_unlock() */
+