Skip to content

Commit

Permalink
Switch mirror writer to use internal H5FD*_test() routines
Browse files Browse the repository at this point in the history
Signed-off-by: Quincey Koziol <[email protected]>
  • Loading branch information
qkoziol committed Apr 19, 2024
1 parent f07671e commit 1d104c9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 95 deletions.
2 changes: 2 additions & 0 deletions src/H5FDpkg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
54 changes: 54 additions & 0 deletions src/H5FDtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
*
Expand Down
2 changes: 1 addition & 1 deletion src/H5private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/

Expand Down
102 changes: 8 additions & 94 deletions utils/mirror_vfd/mirror_writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
}
Expand All @@ -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() */

Expand Down Expand Up @@ -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;
Expand All @@ -437,9 +419,6 @@ do_close(struct mirror_session *session)
return -1;
}

if (api_ctx_pushed)
H5CX_pop(false);

return 0;
} /* end do_close() */

Expand All @@ -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");
Expand All @@ -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;
Expand All @@ -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() */

Expand All @@ -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));
Expand Down Expand Up @@ -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");
Expand All @@ -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
{
Expand All @@ -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");
Expand All @@ -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;
Expand All @@ -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() */

Expand All @@ -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;
Expand All @@ -703,9 +641,6 @@ do_truncate(struct mirror_session *session)
return -1;
}

if (api_ctx_pushed)
H5CX_pop(false);

return 0;
} /* end do_truncate() */

Expand All @@ -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;
Expand All @@ -744,9 +671,6 @@ do_unlock(struct mirror_session *session)
return -1;
}

if (api_ctx_pushed)
H5CX_pop(false);

return 0;
} /* end do_unlock() */

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand All @@ -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");
Expand All @@ -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() */

Expand Down

0 comments on commit 1d104c9

Please sign in to comment.