mirror of
https://github.com/HDFGroup/hdf5.git
synced 2024-11-27 02:10:55 +08:00
Cleanup of mirror VFD test code (#1949)
This commit is contained in:
parent
ce4c41f89f
commit
8ed84bf4f0
2907
test/mirror_vfd.c
2907
test/mirror_vfd.c
File diff suppressed because it is too large
Load Diff
@ -139,7 +139,7 @@ setup_parameters(int argc, char *const argv[], options_t *opts)
|
||||
opts->nplanes = (hsize_t)opts->chunksize;
|
||||
|
||||
show_parameters(opts);
|
||||
return (0);
|
||||
return 0;
|
||||
} /* setup_parameters() */
|
||||
|
||||
/* Overall Algorithm:
|
||||
@ -152,17 +152,17 @@ setup_parameters(int argc, char *const argv[], options_t *opts)
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
pid_t childpid = 0;
|
||||
pid_t mypid, tmppid;
|
||||
int child_status;
|
||||
int child_wait_option = 0;
|
||||
int ret_value = 0;
|
||||
int child_ret_value;
|
||||
hbool_t send_wait = FALSE;
|
||||
hid_t fid = -1; /* File ID */
|
||||
H5FD_mirror_fapl_t mirr_fa;
|
||||
H5FD_splitter_vfd_config_t split_fa;
|
||||
hid_t mirr_fapl_id = H5I_INVALID_HID;
|
||||
pid_t childpid = 0;
|
||||
pid_t mypid, tmppid;
|
||||
int child_status;
|
||||
int child_wait_option = 0;
|
||||
int ret_value = 0;
|
||||
int child_ret_value;
|
||||
hbool_t send_wait = FALSE;
|
||||
hid_t fid = H5I_INVALID_HID;
|
||||
H5FD_mirror_fapl_t mirr_fa;
|
||||
H5FD_splitter_vfd_config_t *split_fa = NULL;
|
||||
hid_t mirr_fapl_id = H5I_INVALID_HID;
|
||||
|
||||
if (setup_parameters(argc, argv, &UC_opts) < 0) {
|
||||
Hgoto_error(1);
|
||||
@ -173,13 +173,18 @@ main(int argc, char *argv[])
|
||||
mirr_fa.handshake_port = SERVER_PORT;
|
||||
HDstrncpy(mirr_fa.remote_ip, SERVER_IP, H5FD_MIRROR_MAX_IP_LEN);
|
||||
|
||||
split_fa.wo_fapl_id = H5I_INVALID_HID;
|
||||
split_fa.rw_fapl_id = H5I_INVALID_HID;
|
||||
split_fa.magic = H5FD_SPLITTER_MAGIC;
|
||||
split_fa.version = H5FD_CURR_SPLITTER_VFD_CONFIG_VERSION;
|
||||
split_fa.log_file_path[0] = '\0'; /* none */
|
||||
split_fa.ignore_wo_errs = FALSE;
|
||||
HDstrncpy(split_fa.wo_path, MIRROR_FILE_NAME, H5FD_SPLITTER_PATH_MAX);
|
||||
if (NULL == (split_fa = HDcalloc(1, sizeof(H5FD_splitter_vfd_config_t)))) {
|
||||
HDfprintf(stderr, "can't allocate memory for splitter config\n");
|
||||
Hgoto_error(1);
|
||||
}
|
||||
|
||||
split_fa->wo_fapl_id = H5I_INVALID_HID;
|
||||
split_fa->rw_fapl_id = H5I_INVALID_HID;
|
||||
split_fa->magic = H5FD_SPLITTER_MAGIC;
|
||||
split_fa->version = H5FD_CURR_SPLITTER_VFD_CONFIG_VERSION;
|
||||
split_fa->log_file_path[0] = '\0'; /* none */
|
||||
split_fa->ignore_wo_errs = FALSE;
|
||||
HDstrncpy(split_fa->wo_path, MIRROR_FILE_NAME, H5FD_SPLITTER_PATH_MAX);
|
||||
|
||||
/* Determine the need to send/wait message file*/
|
||||
if (UC_opts.launch == UC_READWRITE) {
|
||||
@ -211,14 +216,14 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
/* Prepare parent "splitter" driver in UC_opts */
|
||||
split_fa.wo_fapl_id = mirr_fapl_id;
|
||||
split_fa.rw_fapl_id = H5P_DEFAULT;
|
||||
UC_opts.fapl_id = H5Pcreate(H5P_FILE_ACCESS);
|
||||
split_fa->wo_fapl_id = mirr_fapl_id;
|
||||
split_fa->rw_fapl_id = H5P_DEFAULT;
|
||||
UC_opts.fapl_id = H5Pcreate(H5P_FILE_ACCESS);
|
||||
if (UC_opts.fapl_id == H5I_INVALID_HID) {
|
||||
HDfprintf(stderr, "can't create creation FAPL\n");
|
||||
Hgoto_error(1);
|
||||
}
|
||||
if (H5Pset_fapl_splitter(UC_opts.fapl_id, &split_fa) < 0) {
|
||||
if (H5Pset_fapl_splitter(UC_opts.fapl_id, split_fa) < 0) {
|
||||
HDfprintf(stderr, "can't set creation FAPL\n");
|
||||
H5Eprint2(H5E_DEFAULT, stdout);
|
||||
Hgoto_error(1);
|
||||
@ -300,14 +305,14 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
/* Prepare parent "splitter" driver in UC_opts */
|
||||
split_fa.wo_fapl_id = mirr_fapl_id;
|
||||
split_fa.rw_fapl_id = H5P_DEFAULT;
|
||||
UC_opts.fapl_id = H5Pcreate(H5P_FILE_ACCESS);
|
||||
split_fa->wo_fapl_id = mirr_fapl_id;
|
||||
split_fa->rw_fapl_id = H5P_DEFAULT;
|
||||
UC_opts.fapl_id = H5Pcreate(H5P_FILE_ACCESS);
|
||||
if (UC_opts.fapl_id == H5I_INVALID_HID) {
|
||||
HDfprintf(stderr, "can't create creation FAPL\n");
|
||||
Hgoto_error(1);
|
||||
}
|
||||
if (H5Pset_fapl_splitter(UC_opts.fapl_id, &split_fa) < 0) {
|
||||
if (H5Pset_fapl_splitter(UC_opts.fapl_id, split_fa) < 0) {
|
||||
HDfprintf(stderr, "can't set creation FAPL\n");
|
||||
H5Eprint2(H5E_DEFAULT, stdout);
|
||||
Hgoto_error(1);
|
||||
@ -368,6 +373,8 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
done:
|
||||
HDfree(split_fa);
|
||||
|
||||
if (ret_value != 0) {
|
||||
HDprintf("Error(s) encountered\n");
|
||||
}
|
||||
@ -375,7 +382,7 @@ done:
|
||||
HDprintf("All passed\n");
|
||||
}
|
||||
|
||||
return (ret_value);
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
#else /* H5_HAVE_MIRROR_VFD */
|
||||
|
@ -471,12 +471,13 @@ wait_for_child(int H5_ATTR_UNUSED sig)
|
||||
static int
|
||||
handle_requests(struct server_run *run)
|
||||
{
|
||||
int connfd = -1; /**/
|
||||
char mybuf[H5FD_MIRROR_XMIT_OPEN_SIZE]; /**/
|
||||
ssize_t ret; /* general-purpose error-checking */
|
||||
int pid; /* process ID of fork */
|
||||
struct sigaction sa;
|
||||
int ret_value = 0;
|
||||
int connfd = -1;
|
||||
char *mybuf = NULL;
|
||||
ssize_t ret; /* general-purpose error-checking */
|
||||
int pid; /* process ID of fork */
|
||||
struct sigaction sa;
|
||||
H5FD_mirror_xmit_open_t *xopen = NULL;
|
||||
int ret_value = 0;
|
||||
|
||||
if (run == NULL || run->magic != SERVER_RUN_MAGIC) {
|
||||
mirror_log(NULL, V_ERR, "invalid server_run pointer");
|
||||
@ -501,6 +502,15 @@ handle_requests(struct server_run *run)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (NULL == (mybuf = HDmalloc(H5FD_MIRROR_XMIT_OPEN_SIZE * sizeof(char)))) {
|
||||
mirror_log(NULL, V_ERR, "out of memory");
|
||||
goto error;
|
||||
}
|
||||
if (NULL == (xopen = HDmalloc(sizeof(H5FD_mirror_xmit_open_t)))) {
|
||||
mirror_log(NULL, V_ERR, "out of memory");
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Keep listening for attempts to connect.
|
||||
*/
|
||||
|
||||
@ -518,7 +528,7 @@ handle_requests(struct server_run *run)
|
||||
/* Read handshake from port connection.
|
||||
*/
|
||||
|
||||
if ((ret = HDread(connfd, &mybuf, H5FD_MIRROR_XMIT_OPEN_SIZE)) < 0) {
|
||||
if ((ret = HDread(connfd, mybuf, H5FD_MIRROR_XMIT_OPEN_SIZE)) < 0) {
|
||||
mirror_log(run->loginfo, V_ERR, "read:%d", ret);
|
||||
goto error;
|
||||
}
|
||||
@ -555,12 +565,11 @@ handle_requests(struct server_run *run)
|
||||
HDclose(connfd);
|
||||
} /* end if "CONFIRM" directive */
|
||||
else if (H5FD_MIRROR_XMIT_OPEN_SIZE == ret) {
|
||||
H5FD_mirror_xmit_open_t xopen;
|
||||
|
||||
mirror_log(run->loginfo, V_INFO, "probable OPEN xmit received");
|
||||
|
||||
H5FD_mirror_xmit_decode_open(&xopen, (const unsigned char *)mybuf);
|
||||
if (FALSE == H5FD_mirror_xmit_is_open(&xopen)) {
|
||||
H5FD_mirror_xmit_decode_open(xopen, (const unsigned char *)mybuf);
|
||||
if (FALSE == H5FD_mirror_xmit_is_open(xopen)) {
|
||||
mirror_log(run->loginfo, V_WARN, "expected OPEN xmit was malformed");
|
||||
HDclose(connfd);
|
||||
continue;
|
||||
@ -575,7 +584,7 @@ handle_requests(struct server_run *run)
|
||||
} /* end if fork error */
|
||||
else if (pid == 0) { /* child process (writer side of fork) */
|
||||
mirror_log(run->loginfo, V_INFO, "executing writer");
|
||||
if (run_writer(connfd, &xopen) < 0) {
|
||||
if (run_writer(connfd, xopen) < 0) {
|
||||
HDprintf("can't run writer\n");
|
||||
}
|
||||
else {
|
||||
@ -605,12 +614,17 @@ done:
|
||||
HDclose(connfd);
|
||||
}
|
||||
|
||||
HDfree(mybuf);
|
||||
HDfree(xopen);
|
||||
|
||||
return ret_value;
|
||||
|
||||
error:
|
||||
if (connfd >= 0) {
|
||||
HDclose(connfd);
|
||||
}
|
||||
HDfree(mybuf);
|
||||
HDfree(xopen);
|
||||
return -1;
|
||||
} /* end handle_requests() */
|
||||
|
||||
|
@ -929,25 +929,33 @@ static int
|
||||
process_instructions(struct mirror_session *session)
|
||||
{
|
||||
struct sock_comm comm;
|
||||
char xmit_buf[H5FD_MIRROR_XMIT_BUFFER_MAX]; /* raw bytes */
|
||||
H5FD_mirror_xmit_t xmit_recd; /* for decoded xmit header */
|
||||
char *xmit_buf = NULL; /* raw bytes */
|
||||
size_t buf_size;
|
||||
H5FD_mirror_xmit_t xmit_recd; /* for decoded xmit header */
|
||||
|
||||
HDassert(session && (session->magic == MW_SESSION_MAGIC));
|
||||
|
||||
mirror_log(session->loginfo, V_INFO, "process_instructions()");
|
||||
|
||||
buf_size = H5FD_MIRROR_XMIT_BUFFER_MAX * sizeof(char);
|
||||
|
||||
if (NULL == (xmit_buf = HDmalloc(buf_size))) {
|
||||
mirror_log(session->loginfo, V_ERR, "out of memory");
|
||||
goto error;
|
||||
}
|
||||
|
||||
comm.magic = MW_SOCK_COMM_MAGIC;
|
||||
comm.recd_die = 0; /* Flag for program to terminate */
|
||||
comm.xmit_recd = &xmit_recd;
|
||||
comm.raw = xmit_buf;
|
||||
comm.raw_size = sizeof(xmit_buf);
|
||||
comm.raw_size = buf_size;
|
||||
|
||||
while (1) { /* sill-listening infinite loop */
|
||||
|
||||
/* Use convenience structure for raw/decoded info in/out */
|
||||
if (receive_communique(session, &comm) < 0) {
|
||||
mirror_log(session->loginfo, V_ERR, "problem reading socket");
|
||||
return -1;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (comm.recd_die) {
|
||||
@ -957,42 +965,42 @@ process_instructions(struct mirror_session *session)
|
||||
switch (xmit_recd.op) {
|
||||
case H5FD_MIRROR_OP_CLOSE:
|
||||
if (do_close(session) < 0) {
|
||||
return -1;
|
||||
goto error;
|
||||
}
|
||||
goto done;
|
||||
case H5FD_MIRROR_OP_LOCK:
|
||||
if (do_lock(session, (const unsigned char *)xmit_buf) < 0) {
|
||||
return -1;
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
case H5FD_MIRROR_OP_OPEN:
|
||||
mirror_log(session->loginfo, V_ERR, "OPEN xmit during session");
|
||||
reply_error(session, "illegal OPEN xmit during session");
|
||||
return -1;
|
||||
goto error;
|
||||
case H5FD_MIRROR_OP_SET_EOA:
|
||||
if (do_set_eoa(session, (const unsigned char *)xmit_buf) < 0) {
|
||||
return -1;
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
case H5FD_MIRROR_OP_TRUNCATE:
|
||||
if (do_truncate(session) < 0) {
|
||||
return -1;
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
case H5FD_MIRROR_OP_UNLOCK:
|
||||
if (do_unlock(session) < 0) {
|
||||
return -1;
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
case H5FD_MIRROR_OP_WRITE:
|
||||
if (do_write(session, (const unsigned char *)xmit_buf) < 0) {
|
||||
return -1;
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
mirror_log(session->loginfo, V_ERR, "unrecognized transmission");
|
||||
reply_error(session, "unrecognized transmission");
|
||||
return -1;
|
||||
goto error;
|
||||
} /* end switch (xmit_recd.op) */
|
||||
|
||||
} /* end while still listening */
|
||||
@ -1000,7 +1008,12 @@ process_instructions(struct mirror_session *session)
|
||||
done:
|
||||
comm.magic = 0; /* invalidate structure, on principle */
|
||||
xmit_recd.magic = 0; /* invalidate structure, on principle */
|
||||
HDfree(xmit_buf);
|
||||
return 0;
|
||||
|
||||
error:
|
||||
HDfree(xmit_buf);
|
||||
return -1;
|
||||
} /* end process_instructions() */
|
||||
|
||||
/* ---------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user