From 0d8529055da9ab23162e698309cc6da1dd93f99e Mon Sep 17 00:00:00 2001 From: Dana Robinson <43805+derobins@users.noreply.github.com> Date: Thu, 14 Jan 2021 06:19:48 -0800 Subject: Removes lock/unlock callbacks from ros3 and hdfs VFDs (#258) * Removes no-op callback stubs from read-only VFDs Also changes VFD registration to allow read-only VFDs with no write callback to be registered. * Adds a RELEASE.txt note for HDFFV-11205 For the read-only VFD registration change * Revert "Removes no-op callback stubs from read-only VFDs" This reverts commit a7a95497305d64d2de783fdb0e3186a532446a4a. * Removes lock callbacks from ros3 and hdfs VFDs --- release_docs/RELEASE.txt | 14 -------- src/H5FD.c | 10 ++---- src/H5FDhdfs.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++-- src/H5FDint.c | 4 --- src/H5FDros3.c | 82 ++++++++++++++++++++++++++++++++++++++++++++-- test/hdfs.c | 9 ------ test/ros3.c | 9 ------ 7 files changed, 164 insertions(+), 48 deletions(-) diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index d2a7a23..262ae00 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -356,20 +356,6 @@ New Features Library: -------- - - H5FDregister() now allows registration of read-only VFDs - - The H5FDregister() call required a VFD to have a write callback, - which prevented registering read-only VFDs like the read-only S3 - (ros3) and HDFS (hdfs) VFDs from being registered unless they - implemented a no-op, fail-always write callback. - - The registration checks no longer check for a write callback and - the no-op stubs have been removed from the ros3 and hdfs VFDs. - If a write operation is called on a VFD with no write callback, a - normal HDF5 error is returned. - - (DER - 2021/01/12, HDFFV-11205) - - Replaced H5E_ATOM with H5E_ID in H5Epubgen.h The term "atom" is archaic and not in line with current HDF5 library diff --git a/src/H5FD.c b/src/H5FD.c index 5498644..d12bb57 100644 --- a/src/H5FD.c +++ b/src/H5FD.c @@ -231,9 +231,9 @@ H5FDregister(const H5FD_class_t *cls) "'get_eoa' and/or 'set_eoa' methods are not defined") if (!cls->get_eof) HGOTO_ERROR(H5E_ARGS, H5E_UNINITIALIZED, H5I_INVALID_HID, "'get_eof' method is not defined") - if (!cls->read) + if (!cls->read || !cls->write) HGOTO_ERROR(H5E_ARGS, H5E_UNINITIALIZED, H5I_INVALID_HID, - "'read' method is not defined") + "'read' and/or 'write' method is not defined") for (type = H5FD_MEM_DEFAULT; type < H5FD_MEM_NTYPES; type++) if (cls->fl_map[type] < H5FD_MEM_NOLIST || cls->fl_map[type] >= H5FD_MEM_NTYPES) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid free-list mapping") @@ -277,7 +277,7 @@ H5FD_register(const void *_cls, size_t size, hbool_t app_ref) HDassert(cls->open && cls->close); HDassert(cls->get_eoa && cls->set_eoa); HDassert(cls->get_eof); - HDassert(cls->read); + HDassert(cls->read && cls->write); for (type = H5FD_MEM_DEFAULT; type < H5FD_MEM_NTYPES; type++) { HDassert(cls->fl_map[type] >= H5FD_MEM_NOLIST && cls->fl_map[type] < H5FD_MEM_NTYPES); } @@ -1417,10 +1417,6 @@ H5FDwrite(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t siz if (!buf) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "result buffer parameter can't be NULL") - /* Make sure this isn't being called on a read-only VFD */ - if (!file->cls->write) - HGOTO_ERROR(H5E_VFL, H5E_WRITEERROR, FAIL, "write request made to read-only VFD") - /* Get the default dataset transfer property list if the user didn't provide one */ if (H5P_DEFAULT == dxpl_id) dxpl_id = H5P_DATASET_XFER_DEFAULT; diff --git a/src/H5FDhdfs.c b/src/H5FDhdfs.c index 1b28168..61c694d 100644 --- a/src/H5FDhdfs.c +++ b/src/H5FDhdfs.c @@ -271,6 +271,10 @@ static haddr_t H5FD__hdfs_get_eof(const H5FD_t *_file, H5FD_mem_t type); static herr_t H5FD__hdfs_get_handle(H5FD_t *_file, hid_t fapl, void **file_handle); static herr_t H5FD__hdfs_read(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id, haddr_t addr, size_t size, void *buf); +static herr_t H5FD__hdfs_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__hdfs_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing); + static herr_t H5FD__hdfs_validate_config(const H5FD_hdfs_fapl_t *fa); static const H5FD_class_t H5FD_hdfs_g = { @@ -300,9 +304,9 @@ static const H5FD_class_t H5FD_hdfs_g = { H5FD__hdfs_get_eof, /* get_eof */ H5FD__hdfs_get_handle, /* get_handle */ H5FD__hdfs_read, /* read */ - NULL, /* write */ + H5FD__hdfs_write, /* write */ NULL, /* flush */ - NULL, /* truncate */ + H5FD__hdfs_truncate, /* truncate */ NULL, /* lock */ NULL, /* unlock */ H5FD_FLMAP_DICHOTOMY /* fl_map */ @@ -667,7 +671,7 @@ H5Pget_fapl_hdfs(hid_t fapl_id, H5FD_hdfs_fapl_t *fa_dst /*out*/) HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "bad VFL driver info") /* Copy the hdfs fapl data out */ - H5MM_memcpy(fs_dst, fa_src, sizeof(H5FD_hdfs_fapl_t)); + H5MM_memcpy(fa_dst, fa_src, sizeof(H5FD_hdfs_fapl_t)); done: FUNC_LEAVE_API(ret_value) @@ -1565,4 +1569,78 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5FD__hdfs_read() */ +/*------------------------------------------------------------------------- + * + * Function: H5FD__hdfs_write() + * + * Purpose: + * + * Write bytes to file. + * UNSUPPORTED IN READ-ONLY HDFS VFD. + * + * Return: + * + * FAIL (Not possible with Read-Only S3 file.) + * + * Programmer: Jacob Smith + * 2017-10-23 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5FD__hdfs_write(H5FD_t H5_ATTR_UNUSED *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNUSED dxpl_id, + haddr_t H5_ATTR_UNUSED addr, size_t H5_ATTR_UNUSED size, const void H5_ATTR_UNUSED *buf) +{ + herr_t ret_value = FAIL; + + FUNC_ENTER_STATIC + +#if HDFS_DEBUG + HDfprintf(stdout, "called %s.\n", FUNC); +#endif + + HGOTO_ERROR(H5E_VFL, H5E_UNSUPPORTED, FAIL, "cannot write to read-only file") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5FD__hdfs_write() */ + +/*------------------------------------------------------------------------- + * + * Function: H5FD__hdfs_truncate() + * + * Purpose: + * + * Makes sure that the true file size is the same (or larger) + * than the end-of-address. + * + * NOT POSSIBLE ON READ-ONLY S3 FILES. + * + * Return: + * + * FAIL (Not possible on Read-Only S3 files.) + * + * Programmer: Jacob Smith + * 2017-10-23 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5FD__hdfs_truncate(H5FD_t H5_ATTR_UNUSED *_file, hid_t H5_ATTR_UNUSED dxpl_id, + hbool_t H5_ATTR_UNUSED closing) +{ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_STATIC + +#if HDFS_DEBUG + HDfprintf(stdout, "called %s.\n", FUNC); +#endif + + HGOTO_ERROR(H5E_VFL, H5E_UNSUPPORTED, FAIL, "cannot truncate read-only file") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5FD__hdfs_truncate() */ + #endif /* H5_HAVE_LIBHDFS */ diff --git a/src/H5FDint.c b/src/H5FDint.c index 8c93f1c..b651c23 100644 --- a/src/H5FDint.c +++ b/src/H5FDint.c @@ -215,10 +215,6 @@ H5FD_write(H5FD_t *file, H5FD_mem_t type, haddr_t addr, size_t size, const void HDassert(file->cls); HDassert(buf); - /* Make sure this isn't being called on a read-only VFD */ - if (!file->cls->write) - HGOTO_ERROR(H5E_VFL, H5E_WRITEERROR, FAIL, "write request made to read-only VFD") - /* Get proper DXPL for I/O */ dxpl_id = H5CX_get_dxpl(); diff --git a/src/H5FDros3.c b/src/H5FDros3.c index df90528..78fbdb1 100644 --- a/src/H5FDros3.c +++ b/src/H5FDros3.c @@ -228,6 +228,10 @@ static haddr_t H5FD__ros3_get_eof(const H5FD_t *_file, H5FD_mem_t type); static herr_t H5FD__ros3_get_handle(H5FD_t *_file, hid_t fapl, void **file_handle); static herr_t H5FD__ros3_read(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id, haddr_t addr, size_t size, void *buf); +static herr_t H5FD__ros3_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__ros3_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing); + static herr_t H5FD__ros3_validate_config(const H5FD_ros3_fapl_t *fa); static const H5FD_class_t H5FD_ros3_g = { @@ -257,9 +261,9 @@ static const H5FD_class_t H5FD_ros3_g = { H5FD__ros3_get_eof, /* get_eof */ H5FD__ros3_get_handle, /* get_handle */ H5FD__ros3_read, /* read */ - NULL, /* write */ + H5FD__ros3_write, /* write */ NULL, /* flush */ - NULL, /* truncate */ + H5FD__ros3_truncate, /* truncate */ NULL, /* lock */ NULL, /* unlock */ H5FD_FLMAP_DICHOTOMY /* fl_map */ @@ -1501,4 +1505,78 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5FD__ros3_read() */ +/*------------------------------------------------------------------------- + * + * Function: H5FD__ros3_write() + * + * Purpose: + * + * Write bytes to file. + * UNSUPPORTED IN READ-ONLY ROS3 VFD. + * + * Return: + * + * FAIL (Not possible with Read-Only S3 file.) + * + * Programmer: Jacob Smith + * 2017-10-23 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5FD__ros3_write(H5FD_t H5_ATTR_UNUSED *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNUSED dxpl_id, + haddr_t H5_ATTR_UNUSED addr, size_t H5_ATTR_UNUSED size, const void H5_ATTR_UNUSED *buf) +{ + herr_t ret_value = FAIL; + + FUNC_ENTER_STATIC + +#if ROS3_DEBUG + HDfprintf(stdout, "H5FD__ros3_write() called.\n"); +#endif + + HGOTO_ERROR(H5E_VFL, H5E_UNSUPPORTED, FAIL, "cannot write to read-only file.") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5FD__ros3_write() */ + +/*------------------------------------------------------------------------- + * + * Function: H5FD__ros3_truncate() + * + * Purpose: + * + * Makes sure that the true file size is the same (or larger) + * than the end-of-address. + * + * NOT POSSIBLE ON READ-ONLY S3 FILES. + * + * Return: + * + * FAIL (Not possible on Read-Only S3 files.) + * + * Programmer: Jacob Smith + * 2017-10-23 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5FD__ros3_truncate(H5FD_t H5_ATTR_UNUSED *_file, hid_t H5_ATTR_UNUSED dxpl_id, + hbool_t H5_ATTR_UNUSED closing) +{ + herr_t ret_value = SUCCEED; + + FUNC_ENTER_STATIC + +#if ROS3_DEBUG + HDfprintf(stdout, "H5FD__ros3_truncate() called.\n"); +#endif + + HGOTO_ERROR(H5E_VFL, H5E_UNSUPPORTED, FAIL, "cannot truncate read-only file.") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5FD__ros3_truncate() */ + #endif /* H5_HAVE_ROS3_VFD */ diff --git a/test/hdfs.c b/test/hdfs.c index 4121f15..e824c48 100644 --- a/test/hdfs.c +++ b/test/hdfs.c @@ -1430,15 +1430,6 @@ test_noops_and_autofails(void) H5E_BEGIN_TRY{ JSVERIFY(FAIL, H5FDtruncate(file, H5P_DEFAULT, TRUE), "truncate must fail (closing)")} H5E_END_TRY; - /* no-op calls to `lock()` and `unlock()` - */ - JSVERIFY(SUCCEED, H5FDlock(file, TRUE), "lock always succeeds; has no effect") - JSVERIFY(SUCCEED, H5FDlock(file, FALSE), "lock issue") - JSVERIFY(SUCCEED, H5FDunlock(file), "unlock issue") - /* Lock/unlock with null file or similar error crashes tests. - * HDassert in calling heirarchy, `H5FD[un]lock()` and `H5FD_[un]lock()` - */ - /************ * TEARDOWN * ************/ diff --git a/test/ros3.c b/test/ros3.c index 654082b..e577ce0 100644 --- a/test/ros3.c +++ b/test/ros3.c @@ -1426,15 +1426,6 @@ test_noops_and_autofails(void) H5E_BEGIN_TRY{ JSVERIFY(FAIL, H5FDtruncate(file, H5P_DEFAULT, TRUE), "truncate must fail (closing)")} H5E_END_TRY; - /* no-op calls to `lock()` and `unlock()` - */ - JSVERIFY(SUCCEED, H5FDlock(file, TRUE), "lock always succeeds; has no effect") - JSVERIFY(SUCCEED, H5FDlock(file, FALSE), NULL) - JSVERIFY(SUCCEED, H5FDunlock(file), NULL) - /* Lock/unlock with null file or similar error crashes tests. - * HDassert in calling heirarchy, `H5FD[un]lock()` and `H5FD_[un]lock()` - */ - /************ * TEARDOWN * ************/ -- cgit v0.12