summaryrefslogtreecommitdiffstats
path: root/src/H5FDdirect.c
diff options
context:
space:
mode:
authorDana Robinson <43805+derobins@users.noreply.github.com>2022-03-06 23:33:00 (GMT)
committerGitHub <noreply@github.com>2022-03-06 23:33:00 (GMT)
commit78375882485a99a81caa933928ed08d7a38ef88b (patch)
treef18c41d7794d546b6562dd2aa36932c78f00a16a /src/H5FDdirect.c
parent7e176db164d1a6f944e703c612c4952b15d333f4 (diff)
downloadhdf5-78375882485a99a81caa933928ed08d7a38ef88b.zip
hdf5-78375882485a99a81caa933928ed08d7a38ef88b.tar.gz
hdf5-78375882485a99a81caa933928ed08d7a38ef88b.tar.bz2
VFD SWMR: normalization with develop (#1472)
Much normalization with develop. Still needs tools changes wrt VFD plugins.
Diffstat (limited to 'src/H5FDdirect.c')
-rw-r--r--src/H5FDdirect.c136
1 files changed, 75 insertions, 61 deletions
diff --git a/src/H5FDdirect.c b/src/H5FDdirect.c
index a1b7b7e..7a43117 100644
--- a/src/H5FDdirect.c
+++ b/src/H5FDdirect.c
@@ -120,6 +120,8 @@ typedef struct H5FD_direct_t {
/* Prototypes */
static herr_t H5FD__direct_term(void);
+static herr_t H5FD__direct_populate_config(size_t boundary, size_t block_size, size_t cbuf_size,
+ H5FD_direct_fapl_t *fa_out);
static void * H5FD__direct_fapl_get(H5FD_t *file);
static void * H5FD__direct_fapl_copy(const void *_old_fa);
static H5FD_t *H5FD__direct_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr);
@@ -140,6 +142,7 @@ static herr_t H5FD__direct_unlock(H5FD_t *_file);
static herr_t H5FD__direct_delete(const char *filename, hid_t fapl_id);
static const H5FD_class_t H5FD_direct_g = {
+ H5FD_DIRECT_VALUE, /* value */
"direct", /* name */
MAXADDR, /* maxaddr */
H5F_CLOSE_WEAK, /* fc_degree */
@@ -172,48 +175,13 @@ static const H5FD_class_t H5FD_direct_g = {
H5FD__direct_lock, /* lock */
H5FD__direct_unlock, /* unlock */
H5FD__direct_delete, /* del */
+ NULL, /* ctl */
H5FD_FLMAP_DICHOTOMY /* fl_map */
};
/* Declare a free list to manage the H5FD_direct_t struct */
H5FL_DEFINE_STATIC(H5FD_direct_t);
-/*--------------------------------------------------------------------------
-NAME
- H5FD__init_package -- Initialize interface-specific information
-USAGE
- herr_t H5FD__init_package()
-RETURNS
- Non-negative on success/Negative on failure
-DESCRIPTION
- Initializes any interface-specific data or routines. (Just calls
- H5FD_direct_init currently).
-
---------------------------------------------------------------------------*/
-static herr_t
-H5FD__init_package(void)
-{
- char * lock_env_var = NULL; /* Environment variable pointer */
- herr_t ret_value = SUCCEED;
-
- FUNC_ENTER_STATIC
-
- /* Check the use disabled file locks environment variable */
- lock_env_var = HDgetenv("HDF5_USE_FILE_LOCKING");
- if (lock_env_var && !HDstrcmp(lock_env_var, "BEST_EFFORT"))
- ignore_disabled_file_locks_s = TRUE; /* Override: Ignore disabled locks */
- else if (lock_env_var && (!HDstrcmp(lock_env_var, "TRUE") || !HDstrcmp(lock_env_var, "1")))
- ignore_disabled_file_locks_s = FALSE; /* Override: Don't ignore disabled locks */
- else
- ignore_disabled_file_locks_s = FAIL; /* Environment variable not set, or not set correctly */
-
- if (H5FD_direct_init() < 0)
- HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "unable to initialize direct VFD")
-
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-} /* H5FD__init_package() */
-
/*-------------------------------------------------------------------------
* Function: H5FD_direct_init
*
@@ -231,12 +199,25 @@ done:
hid_t
H5FD_direct_init(void)
{
- hid_t ret_value = H5I_INVALID_HID; /* Return value */
+ char *lock_env_var = NULL; /* Environment variable pointer */
+ hid_t ret_value = H5I_INVALID_HID; /* Return value */
FUNC_ENTER_NOAPI(H5I_INVALID_HID)
- if (H5I_VFL != H5I_get_type(H5FD_DIRECT_g))
+ /* Check the use disabled file locks environment variable */
+ lock_env_var = HDgetenv(HDF5_USE_FILE_LOCKING);
+ if (lock_env_var && !HDstrcmp(lock_env_var, "BEST_EFFORT"))
+ ignore_disabled_file_locks_s = TRUE; /* Override: Ignore disabled locks */
+ else if (lock_env_var && (!HDstrcmp(lock_env_var, "TRUE") || !HDstrcmp(lock_env_var, "1")))
+ ignore_disabled_file_locks_s = FALSE; /* Override: Don't ignore disabled locks */
+ else
+ ignore_disabled_file_locks_s = FAIL; /* Environment variable not set, or not set correctly */
+
+ if (H5I_VFL != H5I_get_type(H5FD_DIRECT_g)) {
H5FD_DIRECT_g = H5FD_register(&H5FD_direct_g, sizeof(H5FD_class_t), FALSE);
+ if (H5I_INVALID_HID == H5FD_DIRECT_g)
+ HGOTO_ERROR(H5E_ID, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register direct");
+ }
/* Set return value */
ret_value = H5FD_DIRECT_g;
@@ -295,28 +276,10 @@ H5Pset_fapl_direct(hid_t fapl_id, size_t boundary, size_t block_size, size_t cbu
if (NULL == (plist = H5P_object_verify(fapl_id, H5P_FILE_ACCESS)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list")
- HDmemset(&fa, 0, sizeof(H5FD_direct_fapl_t));
- if (boundary != 0)
- fa.mboundary = boundary;
- else
- fa.mboundary = MBOUNDARY_DEF;
- if (block_size != 0)
- fa.fbsize = block_size;
- else
- fa.fbsize = FBSIZE_DEF;
- if (cbuf_size != 0)
- fa.cbsize = cbuf_size;
- else
- fa.cbsize = CBSIZE_DEF;
-
- /* Set the default to be true for data alignment */
- fa.must_align = TRUE;
-
- /* Copy buffer size must be a multiple of file block size */
- if (fa.cbsize % fa.fbsize != 0)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "copy buffer size must be a multiple of block size")
+ if (H5FD__direct_populate_config(boundary, block_size, cbuf_size, &fa) < 0)
+ HGOTO_ERROR(H5E_VFL, H5E_CANTSET, FAIL, "can't initialize driver configuration info")
- ret_value = H5P_set_driver(plist, H5FD_DIRECT, &fa);
+ ret_value = H5P_set_driver(plist, H5FD_DIRECT, &fa, NULL);
done:
FUNC_LEAVE_API(ret_value)
@@ -366,6 +329,53 @@ done:
} /* end H5Pget_fapl_direct() */
/*-------------------------------------------------------------------------
+ * Function: H5FD__direct_populate_config
+ *
+ * Purpose: Populates a H5FD_direct_fapl_t structure with the provided
+ * values, supplying defaults where values are not provided.
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5FD__direct_populate_config(size_t boundary, size_t block_size, size_t cbuf_size, H5FD_direct_fapl_t *fa_out)
+{
+ herr_t ret_value = SUCCEED;
+
+ FUNC_ENTER_STATIC
+
+ HDassert(fa_out);
+
+ HDmemset(fa_out, 0, sizeof(H5FD_direct_fapl_t));
+
+ if (boundary != 0)
+ fa_out->mboundary = boundary;
+ else
+ fa_out->mboundary = MBOUNDARY_DEF;
+
+ if (block_size != 0)
+ fa_out->fbsize = block_size;
+ else
+ fa_out->fbsize = FBSIZE_DEF;
+
+ if (cbuf_size != 0)
+ fa_out->cbsize = cbuf_size;
+ else
+ fa_out->cbsize = CBSIZE_DEF;
+
+ /* Set the default to be true for data alignment */
+ fa_out->must_align = TRUE;
+
+ /* Copy buffer size must be a multiple of file block size */
+ if (fa_out->cbsize % fa_out->fbsize != 0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "copy buffer size must be a multiple of block size")
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5FD__direct_populate_config() */
+
+/*-------------------------------------------------------------------------
* Function: H5FD__direct_fapl_get
*
* Purpose: Returns a file access property list which indicates how the
@@ -449,6 +459,7 @@ H5FD__direct_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxad
int fd = (-1);
H5FD_direct_t * file = NULL;
const H5FD_direct_fapl_t *fa;
+ H5FD_direct_fapl_t default_fa;
#ifdef H5_HAVE_WIN32_API
HFILE filehandle;
struct _BY_HANDLE_FILE_INFORMATION fileinfo;
@@ -497,8 +508,11 @@ H5FD__direct_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxad
/* Get the driver specific information */
if (NULL == (plist = H5P_object_verify(fapl_id, H5P_FILE_ACCESS)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file access property list")
- if (NULL == (fa = (const H5FD_direct_fapl_t *)H5P_peek_driver_info(plist)))
- HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, NULL, "bad VFL driver info")
+ if (NULL == (fa = (const H5FD_direct_fapl_t *)H5P_peek_driver_info(plist))) {
+ if (H5FD__direct_populate_config(0, 0, 0, &default_fa) < 0)
+ HGOTO_ERROR(H5E_VFL, H5E_CANTSET, NULL, "can't initialize driver configuration info")
+ fa = &default_fa;
+ }
file->fd = fd;
H5_CHECKED_ASSIGN(file->eof, haddr_t, sb.st_size, h5_stat_size_t);