From 1d104c95f33bc5f71192ce2f6e5d1ef78835ebfe Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Fri, 19 Apr 2024 17:47:06 -0500 Subject: [PATCH] Switch mirror writer to use internal H5FD*_test() routines Signed-off-by: Quincey Koziol --- src/H5FDpkg.h | 2 + src/H5FDtest.c | 54 ++++++++++++++++ src/H5private.h | 2 +- utils/mirror_vfd/mirror_writer.c | 102 +++---------------------------- 4 files changed, 65 insertions(+), 95 deletions(-) diff --git a/src/H5FDpkg.h b/src/H5FDpkg.h index 68237a4a10a..83b52d4bb96 100644 --- a/src/H5FDpkg.h +++ b/src/H5FDpkg.h @@ -69,6 +69,8 @@ H5_DLL herr_t H5FDwrite_selection_test(H5FD_t *file, H5FD_mem_t type, hid_t dxp hid_t mem_spaces[], hid_t file_spaces[], haddr_t offsets[], size_t element_sizes[], const void *bufs[]); H5_DLL herr_t H5FDtruncate_test(H5FD_t *file, hid_t dxpl_id, hbool_t closing); +H5_DLL herr_t H5FDlock_test(H5FD_t *file, hbool_t rw); +H5_DLL herr_t H5FDunlock_test(H5FD_t *file); H5_DLL herr_t H5FDctl_test(H5FD_t *file, uint64_t op_code, uint64_t flags, const void *input, void **output); H5_DLL bool H5FD__supports_swmr_test(const char *vfd_name); #endif /* H5FD_TESTING */ diff --git a/src/H5FDtest.c b/src/H5FDtest.c index 9ee8d15894b..2fbd7998a3c 100644 --- a/src/H5FDtest.c +++ b/src/H5FDtest.c @@ -419,6 +419,60 @@ H5FDtruncate_test(H5FD_t *file, hid_t dxpl_id, hbool_t closing) FUNC_LEAVE_API(ret_value) } /* end H5FDtruncate_test() */ +/*------------------------------------------------------------------------- + * Function: H5FDlock_test() + * + * Purpose: Wrapper for using H5FDlock() in internal tests. Pushes + * an API context, so that the internal routines will have + * one to get values from. + * + * This function is only intended for use in the test code. + * + * Return: Value from underlying routine + * + *------------------------------------------------------------------------- + */ +herr_t +H5FDlock_test(H5FD_t *file, hbool_t rw) +{ + herr_t ret_value; + + FUNC_ENTER_API(FAIL) + + /* Call developer routine */ + ret_value = H5FDlock(file, rw); + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5FDlock_test() */ + +/*------------------------------------------------------------------------- + * Function: H5FDunlock_test() + * + * Purpose: Wrapper for using H5FDunlock() in internal tests. Pushes + * an API context, so that the internal routines will have + * one to get values from. + * + * This function is only intended for use in the test code. + * + * Return: Value from underlying routine + * + *------------------------------------------------------------------------- + */ +herr_t +H5FDunlock_test(H5FD_t *file) +{ + herr_t ret_value; + + FUNC_ENTER_API(FAIL) + + /* Call developer routine */ + ret_value = H5FDunlock(file); + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5FDunlock_test() */ + /*------------------------------------------------------------------------- * Function: H5FDctl_test() * diff --git a/src/H5private.h b/src/H5private.h index f8e923ef9f5..e48582f5c9c 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -1652,7 +1652,7 @@ H5_DLL herr_t H5CX_pop(bool update_dxpl_props); /* Compile-time "assert" macro */ #define HDcompile_assert(e) ((void)sizeof(char[!!(e) ? 1 : -1])) /* Variants that are correct, but generate compile-time warnings in some circumstances: -#define HDcompile_assert(e) do { enum { compile_assert__ = 1 / (e) }; } while(0) + #define HDcompile_assert(e) do { enum { compile_assert__ = 1 / (e) }; } while(0) #define HDcompile_assert(e) do { typedef struct { unsigned int b: (e); } x; } while(0) */ diff --git a/utils/mirror_vfd/mirror_writer.c b/utils/mirror_vfd/mirror_writer.c index 3ef75d5aa28..2a9b47f4fa4 100644 --- a/utils/mirror_vfd/mirror_writer.c +++ b/utils/mirror_vfd/mirror_writer.c @@ -220,23 +220,16 @@ session_init(struct mirror_writer_opts *opts) static int session_stop(struct mirror_session *session) { - bool api_ctx_pushed = false; /* Whether API context pushed */ int ret_value = 0; assert(session && (session->magic == MW_SESSION_MAGIC)); mirror_log(session->loginfo, V_INFO, "session_stop()"); - /* Push API context */ - if (H5CX_push() < 0) - ret_value--; - else - api_ctx_pushed = true; - /* Close HDF5 file if it is still open (probably in error) */ if (session->file) { mirror_log(session->loginfo, V_WARN, "HDF5 file still open at cleanup"); - if (H5FDclose(session->file) < 0) { + if (H5FDclose_test(session->file) < 0) { mirror_log(session->loginfo, V_ERR, "H5FDclose() during cleanup!"); ret_value--; } @@ -255,9 +248,6 @@ session_stop(struct mirror_session *session) session->magic++; free(session); - if (api_ctx_pushed) - H5CX_pop(false); - return ret_value; } /* end session_stop() */ @@ -406,25 +396,17 @@ reply_error(struct mirror_session *session, const char *msg) static int do_close(struct mirror_session *session) { - bool api_ctx_pushed = false; /* Whether API context pushed */ - assert(session && (session->magic == MW_SESSION_MAGIC)); mirror_log(session->loginfo, V_INFO, "do_close()"); - /* Push API context */ - if (H5CX_push() < 0) - return -1; - else - api_ctx_pushed = true; - if (NULL == session->file) { mirror_log(session->loginfo, V_ERR, "no file to close!"); reply_error(session, "no file to close"); return -1; } - if (H5FDclose(session->file) < 0) { + if (H5FDclose_test(session->file) < 0) { mirror_log(session->loginfo, V_ERR, "H5FDclose()"); reply_error(session, "H5FDclose()"); return -1; @@ -437,9 +419,6 @@ do_close(struct mirror_session *session) return -1; } - if (api_ctx_pushed) - H5CX_pop(false); - return 0; } /* end do_close() */ @@ -456,18 +435,11 @@ do_lock(struct mirror_session *session, const unsigned char *xmit_buf) { size_t decode_ret = 0; H5FD_mirror_xmit_lock_t xmit_lock; - bool api_ctx_pushed = false; /* Whether API context pushed */ assert(session && (session->magic == MW_SESSION_MAGIC) && xmit_buf); mirror_log(session->loginfo, V_INFO, "do_lock()"); - /* Push API context */ - if (H5CX_push() < 0) - return -1; - else - api_ctx_pushed = true; - decode_ret = H5FD_mirror_xmit_decode_lock(&xmit_lock, xmit_buf); if (H5FD_MIRROR_XMIT_LOCK_SIZE != decode_ret) { mirror_log(session->loginfo, V_ERR, "can't decode set-eoa xmit"); @@ -482,7 +454,7 @@ do_lock(struct mirror_session *session, const unsigned char *xmit_buf) } mirror_log(session->loginfo, V_INFO, "lock rw: (%d)", xmit_lock.rw); - if (H5FDlock(session->file, (bool)xmit_lock.rw) < 0) { + if (H5FDlock_test(session->file, (bool)xmit_lock.rw) < 0) { mirror_log(session->loginfo, V_ERR, "H5FDlock()"); reply_error(session, "remote H5FDlock() failure"); return -1; @@ -494,9 +466,6 @@ do_lock(struct mirror_session *session, const unsigned char *xmit_buf) return -1; } - if (api_ctx_pushed) - H5CX_pop(false); - return 0; } /* end do_lock() */ @@ -514,7 +483,6 @@ do_open(struct mirror_session *session, const H5FD_mirror_xmit_open_t *xmit_open hid_t fapl_id = H5I_INVALID_HID; unsigned _flags = 0; haddr_t _maxaddr = HADDR_UNDEF; - bool api_ctx_pushed = false; /* Whether API context pushed */ assert(session && (session->magic == MW_SESSION_MAGIC) && xmit_open && true == H5FD_mirror_xmit_is_open(xmit_open)); @@ -564,13 +532,7 @@ do_open(struct mirror_session *session, const H5FD_mirror_xmit_open_t *xmit_open goto error; } - /* Push API context */ - if (H5CX_push() < 0) - goto error; - else - api_ctx_pushed = true; - - session->file = H5FDopen(xmit_open->filename, _flags, fapl_id, _maxaddr); + session->file = H5FDopen_test(xmit_open->filename, _flags, fapl_id, _maxaddr); if (NULL == session->file) { mirror_log(session->loginfo, V_ERR, "H5FDopen()"); reply_error(session, "remote H5FDopen() failure"); @@ -590,15 +552,9 @@ do_open(struct mirror_session *session, const H5FD_mirror_xmit_open_t *xmit_open return -1; } - if (api_ctx_pushed) - H5CX_pop(false); - return 0; error: - if (api_ctx_pushed) - H5CX_pop(false); - if (fapl_id > 0) { H5E_BEGIN_TRY { @@ -622,18 +578,11 @@ do_set_eoa(struct mirror_session *session, const unsigned char *xmit_buf) { size_t decode_ret = 0; H5FD_mirror_xmit_eoa_t xmit_seoa; - bool api_ctx_pushed = false; /* Whether API context pushed */ assert(session && (session->magic == MW_SESSION_MAGIC) && xmit_buf); mirror_log(session->loginfo, V_INFO, "do_set_eoa()"); - /* Push API context */ - if (H5CX_push() < 0) - return -1; - else - api_ctx_pushed = true; - decode_ret = H5FD_mirror_xmit_decode_set_eoa(&xmit_seoa, xmit_buf); if (H5FD_MIRROR_XMIT_EOA_SIZE != decode_ret) { mirror_log(session->loginfo, V_ERR, "can't decode set-eoa xmit"); @@ -649,7 +598,7 @@ do_set_eoa(struct mirror_session *session, const unsigned char *xmit_buf) mirror_log(session->loginfo, V_INFO, "set EOA addr %d", xmit_seoa.eoa_addr); - if (H5FDset_eoa(session->file, (H5FD_mem_t)xmit_seoa.type, (haddr_t)xmit_seoa.eoa_addr) < 0) { + if (H5FDset_eoa_test(session->file, (H5FD_mem_t)xmit_seoa.type, (haddr_t)xmit_seoa.eoa_addr) < 0) { mirror_log(session->loginfo, V_ERR, "H5FDset_eoa()"); reply_error(session, "remote H5FDset_eoa() failure"); return -1; @@ -661,9 +610,6 @@ do_set_eoa(struct mirror_session *session, const unsigned char *xmit_buf) return -1; } - if (api_ctx_pushed) - H5CX_pop(false); - return 0; } /* end do_set_eoa() */ @@ -678,20 +624,12 @@ do_set_eoa(struct mirror_session *session, const unsigned char *xmit_buf) static int do_truncate(struct mirror_session *session) { - bool api_ctx_pushed = false; /* Whether API context pushed */ - assert(session && (session->magic == MW_SESSION_MAGIC)); mirror_log(session->loginfo, V_INFO, "do_truncate()"); - /* Push API context */ - if (H5CX_push() < 0) - return -1; - else - api_ctx_pushed = true; - /* default DXPL ID (0), 0 for "false" closing -- both probably unused */ - if (H5FDtruncate(session->file, 0, 0) < 0) { + if (H5FDtruncate_test(session->file, 0, 0) < 0) { mirror_log(session->loginfo, V_ERR, "H5FDtruncate()"); reply_error(session, "remote H5FDtruncate() failure"); return -1; @@ -703,9 +641,6 @@ do_truncate(struct mirror_session *session) return -1; } - if (api_ctx_pushed) - H5CX_pop(false); - return 0; } /* end do_truncate() */ @@ -720,19 +655,11 @@ do_truncate(struct mirror_session *session) static int do_unlock(struct mirror_session *session) { - bool api_ctx_pushed = false; /* Whether API context pushed */ - assert(session && (session->magic == MW_SESSION_MAGIC)); mirror_log(session->loginfo, V_INFO, "do_unlock()"); - /* Push API context */ - if (H5CX_push() < 0) - return -1; - else - api_ctx_pushed = true; - - if (H5FDunlock(session->file) < 0) { + if (H5FDunlock_test(session->file) < 0) { mirror_log(session->loginfo, V_ERR, "H5FDunlock()"); reply_error(session, "remote H5FDunlock() failure"); return -1; @@ -744,9 +671,6 @@ do_unlock(struct mirror_session *session) return -1; } - if (api_ctx_pushed) - H5CX_pop(false); - return 0; } /* end do_unlock() */ @@ -774,7 +698,6 @@ do_write(struct mirror_session *session, const unsigned char *xmit_buf) char *buf = NULL; ssize_t nbytes_in_packet = 0; H5FD_mirror_xmit_write_t xmit_write; - bool api_ctx_pushed = false; /* Whether API context pushed */ assert(session && (session->magic == MW_SESSION_MAGIC) && xmit_buf); @@ -820,12 +743,6 @@ do_write(struct mirror_session *session, const unsigned char *xmit_buf) mirror_log(session->loginfo, V_INFO, "to write %zu bytes at %zu", xmit_write.size, addr); - /* Push API context */ - if (H5CX_push() < 0) - return -1; - else - api_ctx_pushed = true; - /* The given write may be: * 1. larger than the allowed single buffer size * 2. larger than the native size_t of this system @@ -851,7 +768,7 @@ do_write(struct mirror_session *session, const unsigned char *xmit_buf) mirror_log(session->loginfo, V_INFO, "writing %zd bytes at %zu", nbytes_in_packet, (addr + sum_bytes_written)); - if (H5FDwrite(session->file, type, H5P_DEFAULT, (addr + sum_bytes_written), (size_t)nbytes_in_packet, + if (H5FDwrite_test(session->file, type, H5P_DEFAULT, (addr + sum_bytes_written), (size_t)nbytes_in_packet, buf) < 0) { mirror_log(session->loginfo, V_ERR, "H5FDwrite()"); reply_error(session, "remote H5FDwrite() failure"); @@ -871,9 +788,6 @@ do_write(struct mirror_session *session, const unsigned char *xmit_buf) return -1; } - if (api_ctx_pushed) - H5CX_pop(false); - return 0; } /* end do_write() */