summaryrefslogtreecommitdiffstats
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
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)
-rw-r--r--src/H5FD.c125
-rw-r--r--src/H5FDcore.c90
-rw-r--r--src/H5FDdirect.c87
-rw-r--r--src/H5FDfamily.c82
-rw-r--r--src/H5FDlog.c81
-rw-r--r--src/H5FDmulti.c101
-rw-r--r--src/H5FDpkg.h3
-rw-r--r--src/H5FDprivate.h2
-rw-r--r--src/H5FDpublic.h24
-rw-r--r--src/H5FDsec2.c73
-rw-r--r--src/H5FDstdio.c97
11 files changed, 720 insertions, 45 deletions
diff --git a/src/H5FD.c b/src/H5FD.c
index 9e183bd..2a15fe8 100644
--- a/src/H5FD.c
+++ b/src/H5FD.c
@@ -1733,6 +1733,131 @@ done:
/*-------------------------------------------------------------------------
+ * Function: H5FDlock
+ *
+ * Purpose: Set a file lock
+ *
+ * Return: Success: Non-negative
+ * Failure: Negative
+ *
+ * Programmer: Vailin Choi; March 2015
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5FDlock(H5FD_t *file, hbool_t rw)
+{
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_API(FAIL)
+ H5TRACE2("e", "*xb", file, rw);
+
+ /* Check args */
+ if(!file || !file->cls)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid file pointer")
+
+ /* The real work */
+ if(H5FD_lock(file, rw) < 0)
+ HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "file lock request failed")
+
+done:
+ FUNC_LEAVE_API(ret_value)
+} /* end H5FDlock() */
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5FD_lock
+ *
+ * Purpose: Private version of H5FDlock()
+ *
+ * Return: Success: Non-negative
+ * Failure: Negative
+ *
+ * Programmer: Vailin Choi; May 2013
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5FD_lock(H5FD_t *file, hbool_t rw)
+{
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI(FAIL)
+
+ HDassert(file && file->cls);
+
+ if(file->cls->lock && (file->cls->lock)(file, rw) < 0)
+ HGOTO_ERROR(H5E_VFL, H5E_CANTUPDATE, FAIL, "driver lock request failed")
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5FD_lock() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5FDunlock
+ *
+ * Purpose: Remove a file lock
+ *
+ * Return: Success: Non-negative
+ * Failure: Negative
+ *
+ * Programmer: Vailin Choi; March 2015
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5FDunlock(H5FD_t *file)
+{
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_API(FAIL)
+ H5TRACE1("e", "*x", file);
+
+ /* Check args */
+ if(!file || !file->cls)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid file pointer")
+
+ /* The real work */
+ if(H5FD_unlock(file) < 0)
+ HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "file unlock request failed")
+
+done:
+ FUNC_LEAVE_API(ret_value)
+} /* end H5FDunlock() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5FD_unlock
+ *
+ * Purpose: Private version of H5FDunlock()
+ *
+ * Return: Success: Non-negative
+ * Failure: Negative
+ *
+ * Programmer: Vailin Choi; May 2013
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5FD_unlock(H5FD_t *file)
+{
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI(FAIL)
+
+ HDassert(file && file->cls);
+
+ if(file->cls->unlock && (file->cls->unlock)(file) < 0)
+ HGOTO_ERROR(H5E_VFL, H5E_CANTUPDATE, FAIL, "driver unlock request failed")
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5FD_unlock() */
+
+
+/*-------------------------------------------------------------------------
* Function: H5FD_get_fileno
*
* Purpose: Quick and dirty routine to retrieve the file's 'fileno' value
diff --git a/src/H5FDcore.c b/src/H5FDcore.c
index 17ec07c..f4aa240 100644
--- a/src/H5FDcore.c
+++ b/src/H5FDcore.c
@@ -141,6 +141,8 @@ static herr_t H5FD__core_write(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id, ha
size_t size, const void *buf);
static herr_t H5FD__core_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing);
static herr_t H5FD__core_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing);
+static herr_t H5FD_core_lock(H5FD_t *_file, hbool_t rw);
+static herr_t H5FD_core_unlock(H5FD_t *_file);
static const H5FD_class_t H5FD_core_g = {
"core", /* name */
@@ -172,8 +174,8 @@ static const H5FD_class_t H5FD_core_g = {
H5FD__core_write, /* write */
H5FD__core_flush, /* flush */
H5FD__core_truncate, /* truncate */
- NULL, /* lock */
- NULL, /* unlock */
+ H5FD_core_lock, /* lock */
+ H5FD_core_unlock, /* unlock */
H5FD_FLMAP_DICHOTOMY /* fl_map */
};
@@ -1016,12 +1018,12 @@ H5FD__core_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_ALLOW_FILE_IMAGE; /* OK to use file image feature with this VFD */
- *flags |= H5FD_FEAT_CAN_USE_FILE_IMAGE_CALLBACKS; /* OK to use file image callbacks with this VFD */
+ *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_ALLOW_FILE_IMAGE; /* OK to use file image feature with this VFD */
+ *flags |= H5FD_FEAT_CAN_USE_FILE_IMAGE_CALLBACKS; /* OK to use file image callbacks with this VFD */
/* If the backing store is open, a POSIX file handle is available */
if(file && file->fd >= 0 && file->backing_store)
@@ -1520,3 +1522,75 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD__core_truncate() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5FD_core_lock
+ *
+ * Purpose: To place an advisory lock on a file.
+ * The lock type to apply depends on the parameter "rw":
+ * TRUE--opens for write: an exclusive lock
+ * FALSE--opens for read: a shared lock
+ *
+ * Return: SUCCEED/FAIL
+ *
+ * Programmer: Vailin Choi; May 2013
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5FD_core_lock(H5FD_t *_file, hbool_t rw)
+{
+ H5FD_core_t *file = (H5FD_core_t*)_file; /* VFD file struct */
+ int lock; /* The type of lock */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT
+
+ HDassert(file);
+ if(file->fd >= 0) {
+
+ /* 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")
+ }
+ /* Otherwise a noop */
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5FD_core_lock() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5FD_core_unlock
+ *
+ * Purpose: To remove the existing lock on the file
+ *
+ * Return: SUCCEED/FAIL
+ *
+ * Programmer: Vailin Choi; May 2013
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5FD_core_unlock(H5FD_t *_file)
+{
+ H5FD_core_t *file = (H5FD_core_t*)_file; /* VFD file struct */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT
+
+ HDassert(file);
+
+ if(file->fd >= 0) {
+
+ if(HDflock(file->fd, LOCK_UN) < 0)
+ HSYS_GOTO_ERROR(H5E_FILE, H5E_BADFILE, FAIL, "unable to flock (unlock) file")
+ }
+ /* Otherwise a noop */
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5FD_core_unlock() */
diff --git a/src/H5FDdirect.c b/src/H5FDdirect.c
index de64923..f88fb1e 100644
--- a/src/H5FDdirect.c
+++ b/src/H5FDdirect.c
@@ -93,6 +93,7 @@ typedef struct H5FD_direct_t {
DWORD fileindexlo;
DWORD fileindexhi;
#endif
+
} H5FD_direct_t;
/*
@@ -136,6 +137,9 @@ static herr_t H5FD_direct_read(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id, ha
static herr_t H5FD_direct_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_direct_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing);
+static herr_t H5FD_direct_lock(H5FD_t *_file, hbool_t rw);
+static herr_t H5FD_direct_unlock(H5FD_t *_file);
+
static const H5FD_class_t H5FD_direct_g = {
"direct", /*name */
@@ -166,10 +170,10 @@ static const H5FD_class_t H5FD_direct_g = {
H5FD_direct_read, /*read */
H5FD_direct_write, /*write */
NULL, /*flush */
- H5FD_direct_truncate, /*truncate */
- NULL, /*lock */
- NULL, /*unlock */
- H5FD_FLMAP_DICHOTOMY /*fl_map */
+ H5FD_direct_truncate, /*truncate */
+ H5FD_direct_lock, /*lock */
+ H5FD_direct_unlock, /*unlock */
+ H5FD_FLMAP_DICHOTOMY /*fl_map */
};
/* Declare a free list to manage the H5FD_direct_t struct */
@@ -689,10 +693,10 @@ H5FD_direct_query(const H5FD_t H5_ATTR_UNUSED * _f, 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_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 */
}
FUNC_LEAVE_NOAPI(SUCCEED)
@@ -1307,5 +1311,72 @@ H5FD_direct_truncate(H5FD_t *_file, hid_t H5_ATTR_UNUSED dxpl_id, hbool_t H5_ATT
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_direct_truncate() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5FD_direct_lock
+ *
+ * Purpose: To place an advisory lock on a file.
+ * The lock type to apply depends on the parameter "rw":
+ * TRUE--opens for write: an exclusive lock
+ * FALSE--opens for read: a shared lock
+ *
+ * Return: SUCCEED/FAIL
+ *
+ * Programmer: Vailin Choi; May 2013
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5FD_direct_lock(H5FD_t *_file, hbool_t rw)
+{
+ H5FD_direct_t *file = (H5FD_direct_t*)_file; /* VFD file struct */
+ int lock; /* The type of lock */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT
+
+ HDassert(file);
+
+ /* Determine the type of lock */
+ int 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_direct_lock() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5FD_direct_unlock
+ *
+ * Purpose: To remove the existing lock on the file
+ *
+ * Return: SUCCEED/FAIL
+ *
+ * Programmer: Vailin Choi; May 2013
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5FD_direct_unlock(H5FD_t *_file)
+{
+ H5FD_direct_t *file = (H5FD_direct_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_direct_unlock() */
+
#endif /* H5_HAVE_DIRECT */
diff --git a/src/H5FDfamily.c b/src/H5FDfamily.c
index 7a35612..310b72f 100644
--- a/src/H5FDfamily.c
+++ b/src/H5FDfamily.c
@@ -106,6 +106,8 @@ static herr_t H5FD_family_write(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, h
size_t size, const void *_buf);
static herr_t H5FD_family_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing);
static herr_t H5FD_family_truncate(H5FD_t *_file, hid_t dxpl_id, unsigned closing);
+static herr_t H5FD_family_lock(H5FD_t *_file, hbool_t rw);
+static herr_t H5FD_family_unlock(H5FD_t *_file);
/* The class struct */
static const H5FD_class_t H5FD_family_g = {
@@ -138,8 +140,8 @@ static const H5FD_class_t H5FD_family_g = {
H5FD_family_write, /*write */
H5FD_family_flush, /*flush */
H5FD_family_truncate, /*truncate */
- NULL, /*lock */
- NULL, /*unlock */
+ H5FD_family_lock, /*lock */
+ H5FD_family_unlock, /*unlock */
H5FD_FLMAP_DICHOTOMY /*fl_map */
};
@@ -1302,3 +1304,79 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_family_truncate() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5FD_family_lock
+ *
+ * Purpose: To place an advisory lock on a file.
+ * The lock type to apply depends on the parameter "rw":
+ * TRUE--opens for write: an exclusive lock
+ * FALSE--opens for read: a shared lock
+ *
+ * Return: SUCCEED/FAIL
+ *
+ * Programmer: Vailin Choi; May 2013
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5FD_family_lock(H5FD_t *_file, hbool_t rw)
+{
+ H5FD_family_t *file = (H5FD_family_t *)_file; /* VFD file struct */
+ unsigned u, i; /* Local index variable */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT
+
+ /* Place the lock on all the member files */
+ for(u = 0; u < file->nmembs; u++) {
+ if(file->memb[u]) {
+ if(H5FD_lock(file->memb[u], rw) < 0)
+ break;
+ } /* end if */
+ } /* end for */
+
+ if(u < file->nmembs) { /* Try to unlock the member files done before */
+ for(i = 0; i < u; i++) {
+ if(H5FD_unlock(file->memb[i]) < 0)
+ /* Push error, but keep going*/
+ HDONE_ERROR(H5E_IO, H5E_CANTUNLOCK, FAIL, "unable to unlock member files")
+ }
+ HGOTO_ERROR(H5E_IO, H5E_CANTLOCK, FAIL, "unable to lock member files")
+ } /* end if */
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5FD_family_lock() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5FD_family_unlock
+ *
+ * Purpose: To remove the existing lock on the file
+ *
+ * Return: SUCCEED/FAIL
+ *
+ * Programmer: Vailin Choi; May 2013
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5FD_family_unlock(H5FD_t *_file)
+{
+ H5FD_family_t *file = (H5FD_family_t *)_file; /* VFD file struct */
+ unsigned u; /* Local index variable */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT
+
+ /* Remove the lock on the member files */
+ for(u = 0; u < file->nmembs; u++) {
+ if(file->memb[u]) {
+ if(H5FD_unlock(file->memb[u]) < 0)
+ HGOTO_ERROR(H5E_IO, H5E_CANTUNLOCK, FAIL, "unable to unlock member files")
+ } /* end if */
+ } /* end for */
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5FD_family_unlock() */
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() */
+
diff --git a/src/H5FDmulti.c b/src/H5FDmulti.c
index 92df2ad..181ad39 100644
--- a/src/H5FDmulti.c
+++ b/src/H5FDmulti.c
@@ -135,6 +135,8 @@ static herr_t H5FD_multi_write(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, ha
size_t size, const void *_buf);
static herr_t H5FD_multi_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing);
static herr_t H5FD_multi_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing);
+static herr_t H5FD_multi_lock(H5FD_t *_file, hbool_t rw);
+static herr_t H5FD_multi_unlock(H5FD_t *_file);
/* The class struct */
static const H5FD_class_t H5FD_multi_g = {
@@ -167,8 +169,8 @@ static const H5FD_class_t H5FD_multi_g = {
H5FD_multi_write, /*write */
H5FD_multi_flush, /*flush */
H5FD_multi_truncate, /*truncate */
- NULL, /*lock */
- NULL, /*unlock */
+ H5FD_multi_lock, /*lock */
+ H5FD_multi_unlock, /*unlock */
H5FD_FLMAP_DEFAULT /*fl_map */
};
@@ -1786,6 +1788,101 @@ H5FD_multi_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing)
/*-------------------------------------------------------------------------
+ * Function: H5FD_multi_lock
+ *
+ * Purpose: Place a lock on all multi members.
+ * When there is error in locking a member file, it will not
+ * proceed further and will try to remove the locks of those
+ * member files that are locked before error is encountered.
+ *
+ * Return: Success: 0
+ * Failure: -1
+ *
+ * Programmer: Vailin Choi; March 2015
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5FD_multi_lock(H5FD_t *_file, hbool_t rw)
+{
+ H5FD_multi_t *file = (H5FD_multi_t*)_file;
+ int nerrors = 0;
+ H5FD_mem_t out_mt;
+ static const char *func="H5FD_multi_unlock"; /* Function Name for error reporting */
+
+ /* Clear the error stack */
+ H5Eclear2(H5E_DEFAULT);
+
+ /* Lock all member files */
+ ALL_MEMBERS(mt) {
+ out_mt = mt;
+ if(file->memb[mt]) {
+ H5E_BEGIN_TRY {
+ if(H5FDlock(file->memb[mt], rw) < 0) {
+ nerrors++;
+ break;
+ } /* end if */
+ } H5E_END_TRY;
+ } /* end if */
+ } END_MEMBERS;
+
+ /* Try to unlock the member files that are locked before error is encountered */
+ if(nerrors) {
+ H5FD_mem_t k;
+
+ for(k = H5FD_MEM_DEFAULT; k < out_mt; k = (H5FD_mem_t)(k + 1)) {
+ H5E_BEGIN_TRY {
+ if(H5FDunlock(file->memb[k]) < 0)
+ nerrors++;
+ } H5E_END_TRY;
+ } /* end for */
+ } /* end if */
+
+ if(nerrors)
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "error locking member files", -1)
+ return 0;
+
+} /* H5FD_multi_lock() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5FD_multi_unlock
+ *
+ * Purpose: Remove the lock on all multi members.
+ * It will try to unlock all member files but will record error
+ * encountered.
+ *
+ * Return: Success: 0
+ * Failure: -1
+ *
+ * Programmer: Vailin Choi; March 2015
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5FD_multi_unlock(H5FD_t *_file)
+{
+ H5FD_multi_t *file = (H5FD_multi_t*)_file;
+ int nerrors=0;
+ static const char *func="H5FD_multi_unlock"; /* Function Name for error reporting */
+
+ /* Clear the error stack */
+ H5Eclear2(H5E_DEFAULT);
+
+ ALL_MEMBERS(mt) {
+ if(file->memb[mt])
+ if(H5FDunlock(file->memb[mt]) < 0)
+ nerrors++;
+ } END_MEMBERS;
+
+ if(nerrors)
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "error unlocking member files", -1)
+
+ return 0;
+} /* H5FD_multi_unlock() */
+
+
+/*-------------------------------------------------------------------------
* Function: compute_next
*
* Purpose: Compute the memb_next[] values of the file based on the
diff --git a/src/H5FDpkg.h b/src/H5FDpkg.h
index ef33cf1..a0c1b3a 100644
--- a/src/H5FDpkg.h
+++ b/src/H5FDpkg.h
@@ -57,8 +57,7 @@ H5_DLL haddr_t H5FD_alloc_real(H5FD_t *file, hid_t dxpl_id, H5FD_mem_t type,
H5_DLL herr_t H5FD_free_real(H5FD_t *file, hid_t dxpl_id, H5FD_mem_t type,
haddr_t addr, hsize_t size);
-
-/* Testing routines */
+/* Testing functions */
#ifdef H5FD_TESTING
#endif /* H5FD_TESTING */
diff --git a/src/H5FDprivate.h b/src/H5FDprivate.h
index 412bbef..0f195ce 100644
--- a/src/H5FDprivate.h
+++ b/src/H5FDprivate.h
@@ -141,6 +141,8 @@ H5_DLL herr_t H5FD_write(H5FD_t *file, const H5P_genplist_t *dxpl, H5FD_mem_t ty
haddr_t addr, size_t size, const void *buf);
H5_DLL herr_t H5FD_flush(H5FD_t *file, hid_t dxpl_id, unsigned closing);
H5_DLL herr_t H5FD_truncate(H5FD_t *file, hid_t dxpl_id, hbool_t closing);
+H5_DLL herr_t H5FD_lock(H5FD_t *file, hbool_t rw);
+H5_DLL herr_t H5FD_unlock(H5FD_t *file);
H5_DLL herr_t H5FD_get_fileno(const H5FD_t *file, unsigned long *filenum);
H5_DLL herr_t H5FD_get_vfd_handle(H5FD_t *file, hid_t fapl, void** file_handle);
H5_DLL herr_t H5FD_set_base_addr(H5FD_t *file, haddr_t base_addr);
diff --git a/src/H5FDpublic.h b/src/H5FDpublic.h
index 58066cc..4183d14 100644
--- a/src/H5FDpublic.h
+++ b/src/H5FDpublic.h
@@ -156,13 +156,13 @@ typedef enum H5F_mem_t H5FD_mem_t;
/* Define VFL driver features that can be enabled on a per-driver basis */
/* These are returned with the 'query' function pointer in H5FD_class_t */
/*
- * Defining the H5FD_FEAT_AGGREGATE_METADATA for a VFL driver means that
+ * Defining H5FD_FEAT_AGGREGATE_METADATA for a VFL driver means that
* the library will attempt to allocate a larger block for metadata and
* then sub-allocate each metadata request from that larger block.
*/
#define H5FD_FEAT_AGGREGATE_METADATA 0x00000001
/*
- * Defining the H5FD_FEAT_ACCUMULATE_METADATA for a VFL driver means that
+ * Defining H5FD_FEAT_ACCUMULATE_METADATA for a VFL driver means that
* the library will attempt to cache metadata as it is written to the file
* and build up a larger block of metadata to eventually pass to the VFL
* 'write' routine.
@@ -177,7 +177,7 @@ typedef enum H5F_mem_t H5FD_mem_t;
#define H5FD_FEAT_ACCUMULATE_METADATA_READ 0x00000004
#define H5FD_FEAT_ACCUMULATE_METADATA (H5FD_FEAT_ACCUMULATE_METADATA_WRITE|H5FD_FEAT_ACCUMULATE_METADATA_READ)
/*
- * Defining the H5FD_FEAT_DATA_SIEVE for a VFL driver means that
+ * Defining H5FD_FEAT_DATA_SIEVE for a VFL driver means that
* the library will attempt to cache raw data as it is read from/written to
* a file in a "data seive" buffer. See Rajeev Thakur's papers:
* http://www.mcs.anl.gov/~thakur/papers/romio-coll.ps.gz
@@ -185,13 +185,13 @@ typedef enum H5F_mem_t H5FD_mem_t;
*/
#define H5FD_FEAT_DATA_SIEVE 0x00000008
/*
- * Defining the H5FD_FEAT_AGGREGATE_SMALLDATA for a VFL driver means that
+ * Defining H5FD_FEAT_AGGREGATE_SMALLDATA for a VFL driver means that
* the library will attempt to allocate a larger block for "small" raw data
* and then sub-allocate "small" raw data requests from that larger block.
*/
#define H5FD_FEAT_AGGREGATE_SMALLDATA 0x00000010
/*
- * Defining the H5FD_FEAT_IGNORE_DRVRINFO for a VFL driver means that
+ * Defining H5FD_FEAT_IGNORE_DRVRINFO for a VFL driver means that
* the library will ignore the driver info that is encoded in the file
* for the VFL driver. (This will cause the driver info to be eliminated
* from the file when it is flushed/closed, if the file is opened R/W).
@@ -205,13 +205,13 @@ typedef enum H5F_mem_t H5FD_mem_t;
*/
#define H5FD_FEAT_DIRTY_DRVRINFO_LOAD 0x00000040
/*
- * Defining the H5FD_FEAT_POSIX_COMPAT_HANDLE for a VFL driver means that
+ * Defining H5FD_FEAT_POSIX_COMPAT_HANDLE for a VFL driver means that
* the handle for the VFD (returned with the 'get_handle' callback) is
* of type 'int' and is compatible with POSIX I/O calls.
*/
#define H5FD_FEAT_POSIX_COMPAT_HANDLE 0x00000080
/*
- * Defining the H5FD_FEAT_HAS_MPI for a VFL driver means that
+ * Defining H5FD_FEAT_HAS_MPI for a VFL driver means that
* the driver makes use of MPI communication and code may retrieve
* communicator/rank information from it
*/
@@ -223,13 +223,13 @@ typedef enum H5F_mem_t H5FD_mem_t;
*/
#define H5FD_FEAT_ALLOCATE_EARLY 0x00000200
/*
- * Defining the H5FD_FEAT_ALLOW_FILE_IMAGE for a VFL driver means that
+ * Defining H5FD_FEAT_ALLOW_FILE_IMAGE for a VFL driver means that
* the driver is able to use a file image in the fapl as the initial
* contents of a file.
*/
#define H5FD_FEAT_ALLOW_FILE_IMAGE 0x00000400
/*
- * Defining the H5FD_FEAT_CAN_USE_FILE_IMAGE_CALLBACKS for a VFL driver
+ * Defining H5FD_FEAT_CAN_USE_FILE_IMAGE_CALLBACKS for a VFL driver
* means that the driver is able to use callbacks to make a copy of the
* image to store in memory.
*/
@@ -274,8 +274,8 @@ typedef struct H5FD_class_t {
haddr_t addr, size_t size, const void *buffer);
herr_t (*flush)(H5FD_t *file, hid_t dxpl_id, unsigned closing);
herr_t (*truncate)(H5FD_t *file, hid_t dxpl_id, hbool_t closing);
- herr_t (*lock)(H5FD_t *file, unsigned char *oid, unsigned lock_type, hbool_t last);
- herr_t (*unlock)(H5FD_t *file, unsigned char *oid, hbool_t last);
+ herr_t (*lock)(H5FD_t *file, hbool_t rw);
+ herr_t (*unlock)(H5FD_t *file);
H5FD_mem_t fl_map[H5FD_MEM_NTYPES];
} H5FD_class_t;
@@ -355,6 +355,8 @@ H5_DLL herr_t H5FDwrite(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id,
haddr_t addr, size_t size, const void *buf);
H5_DLL herr_t H5FDflush(H5FD_t *file, hid_t dxpl_id, unsigned closing);
H5_DLL herr_t H5FDtruncate(H5FD_t *file, hid_t dxpl_id, hbool_t closing);
+H5_DLL herr_t H5FDlock(H5FD_t *file, hbool_t rw);
+H5_DLL herr_t H5FDunlock(H5FD_t *file);
#ifdef __cplusplus
}
diff --git a/src/H5FDsec2.c b/src/H5FDsec2.c
index 34527df..bb8f004 100644
--- a/src/H5FDsec2.c
+++ b/src/H5FDsec2.c
@@ -97,6 +97,7 @@ typedef struct H5FD_sec2_t {
* a single file.
*/
hbool_t fam_to_sec2;
+
} H5FD_sec2_t;
/*
@@ -137,6 +138,8 @@ static herr_t H5FD_sec2_read(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id, hadd
static herr_t H5FD_sec2_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_sec2_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing);
+static herr_t H5FD_sec2_lock(H5FD_t *_file, hbool_t rw);
+static herr_t H5FD_sec2_unlock(H5FD_t *_file);
static const H5FD_class_t H5FD_sec2_g = {
"sec2", /* name */
@@ -168,8 +171,8 @@ static const H5FD_class_t H5FD_sec2_g = {
H5FD_sec2_write, /* write */
NULL, /* flush */
H5FD_sec2_truncate, /* truncate */
- NULL, /* lock */
- NULL, /* unlock */
+ H5FD_sec2_lock, /* lock */
+ H5FD_sec2_unlock, /* unlock */
H5FD_FLMAP_DICHOTOMY /* fl_map */
};
@@ -901,3 +904,69 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_sec2_truncate() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5FD_sec2_lock
+ *
+ * Purpose: To place an advisory lock on a file.
+ * The lock type to apply depends on the parameter "rw":
+ * TRUE--opens for write: an exclusive lock
+ * FALSE--opens for read: a shared lock
+ *
+ * Return: SUCCEED/FAIL
+ *
+ * Programmer: Vailin Choi; May 2013
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5FD_sec2_lock(H5FD_t *_file, hbool_t rw)
+{
+ H5FD_sec2_t *file = (H5FD_sec2_t *)_file; /* VFD file struct */
+ int lock; /* The type of lock */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT
+
+ 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_sec2_lock() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5FD_sec2_unlock
+ *
+ * Purpose: To remove the existing lock on the file
+ *
+ * Return: SUCCEED/FAIL
+ *
+ * Programmer: Vailin Choi; May 2013
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5FD_sec2_unlock(H5FD_t *_file)
+{
+ H5FD_sec2_t *file = (H5FD_sec2_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_sec2_unlock() */
+
diff --git a/src/H5FDstdio.c b/src/H5FDstdio.c
index 686e1fc..d5b3d40 100644
--- a/src/H5FDstdio.c
+++ b/src/H5FDstdio.c
@@ -31,6 +31,11 @@
#include "hdf5.h"
+#ifdef H5_HAVE_FLOCK
+/* Needed for lock type definitions (e.g., LOCK_EX) */
+#include <sys/file.h>
+#endif /* H5_HAVE_FLOCK */
+
#ifdef H5_HAVE_UNISTD_H
#include <unistd.h>
#endif
@@ -179,6 +184,8 @@ static herr_t H5FD_stdio_write(H5FD_t *lf, H5FD_mem_t type, hid_t fapl_id, haddr
size_t size, const void *buf);
static herr_t H5FD_stdio_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing);
static herr_t H5FD_stdio_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing);
+static herr_t H5FD_stdio_lock(H5FD_t *_file, hbool_t rw);
+static herr_t H5FD_stdio_unlock(H5FD_t *_file);
static const H5FD_class_t H5FD_stdio_g = {
"stdio", /* name */
@@ -210,8 +217,8 @@ static const H5FD_class_t H5FD_stdio_g = {
H5FD_stdio_write, /* write */
H5FD_stdio_flush, /* flush */
H5FD_stdio_truncate, /* truncate */
- NULL, /* lock */
- NULL, /* unlock */
+ H5FD_stdio_lock, /* lock */
+ H5FD_stdio_unlock, /* unlock */
H5FD_FLMAP_DICHOTOMY /* fl_map */
};
@@ -439,7 +446,7 @@ H5FD_stdio_open( const char *name, unsigned flags, hid_t /*UNUSED*/ fapl_id,
file->inode = sb.st_ino;
#endif /* H5_HAVE_WIN32_API */
- return (H5FD_t*)file;
+ return((H5FD_t*)file);
} /* end H5FD_stdio_open() */
@@ -704,6 +711,9 @@ H5FD_stdio_get_eof(const H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type)
/* Clear the error stack */
H5Eclear2(H5E_DEFAULT);
+ /* Quiet the compiler */
+ type = type;
+
return(file->eof);
} /* end H5FD_stdio_get_eof() */
@@ -1073,6 +1083,87 @@ H5FD_stdio_truncate(H5FD_t *_file, hid_t /*UNUSED*/ dxpl_id,
} /* end H5FD_stdio_truncate() */
+/*-------------------------------------------------------------------------
+ * Function: H5FD_stdio_lock
+ *
+ * Purpose: Lock a file via flock
+ *
+ * NOTE: This function is a no-op if flock() is not present.
+ * Errors:
+ * IO FCNTL flock failed.
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Vailin Choi; March 2015
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5FD_stdio_lock(H5FD_t *_file, hbool_t rw)
+{
+#ifdef H5_HAVE_FLOCK
+ H5FD_stdio_t *file = (H5FD_stdio_t*)_file;
+ int lock; /* The type of lock */
+ static const char *func = "H5FD_stdio_lock"; /* Function Name for error reporting */
+
+ /* Clear the error stack */
+ H5Eclear2(H5E_DEFAULT);
+
+ assert(file);
+
+ /* Determine the type of lock */
+ lock = rw ? LOCK_EX : LOCK_SH;
+
+ /* Place the lock with non-blocking */
+ if(flock(file->fd, lock | LOCK_NB) < 0)
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_FCNTL, "flock failed", -1)
+ if(fflush(file->fp) < 0)
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_WRITEERROR, "fflush failed", -1)
+
+#endif /* H5_HAVE_FLOCK */
+
+ return 0;
+} /* end H5FD_stdio_lock() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5F_stdio_unlock
+ *
+ * Purpose: Unlock a file via flock
+ *
+ *
+ * NOTE: This function is a no-op if flock() is not present.
+ * Errors:
+ * IO FCNTL flock failed.
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Vailin Choi; March 2015
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5FD_stdio_unlock(H5FD_t *_file)
+{
+#ifdef H5_HAVE_FLOCK
+ H5FD_stdio_t *file = (H5FD_stdio_t*)_file;
+ static const char *func = "H5FD_stdio_unlock"; /* Function Name for error reporting */
+
+ /* Clear the error stack */
+ H5Eclear2(H5E_DEFAULT);
+
+ assert(file);
+
+ if(fflush(file->fp) < 0)
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_WRITEERROR, "fflush failed", -1)
+ if(flock(file->fd, LOCK_UN) < 0)
+ H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_FCNTL, "flock (unlock) failed", -1)
+
+#endif /* H5_HAVE_FLOCK */
+
+ return 0;
+} /* end H5FD_stdio_unlock() */
+
+
#ifdef _H5private_H
/*
* This is not related to the functionality of the driver code.