summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorDana Robinson <43805+derobins@users.noreply.github.com>2023-01-05 20:51:25 (GMT)
committerGitHub <noreply@github.com>2023-01-05 20:51:25 (GMT)
commitcedd2a41f5143834084a6e2f609929f19a55cb2b (patch)
tree9ea93a5932b4d47972c3da26527b9225548d1a79 /utils
parent363b26fa0d9dadcd96e611ed38956afeaa94851a (diff)
downloadhdf5-cedd2a41f5143834084a6e2f609929f19a55cb2b.zip
hdf5-cedd2a41f5143834084a6e2f609929f19a55cb2b.tar.gz
hdf5-cedd2a41f5143834084a6e2f609929f19a55cb2b.tar.bz2
Brings mirror VFD test fixes from develop (#2392)
Diffstat (limited to 'utils')
-rw-r--r--utils/mirror_vfd/CMakeLists.txt4
-rw-r--r--utils/mirror_vfd/mirror_server.c64
-rw-r--r--utils/mirror_vfd/mirror_server_stop.c11
-rw-r--r--utils/mirror_vfd/mirror_writer.c37
4 files changed, 84 insertions, 32 deletions
diff --git a/utils/mirror_vfd/CMakeLists.txt b/utils/mirror_vfd/CMakeLists.txt
index 92212e0..4765e2c 100644
--- a/utils/mirror_vfd/CMakeLists.txt
+++ b/utils/mirror_vfd/CMakeLists.txt
@@ -12,7 +12,7 @@ set (mirror_server_SOURCES
${HDF5_UTILS_MIRRORVFD_SOURCE_DIR}/mirror_remote.h
)
add_executable (mirror_server ${mirror_server_SOURCES})
-target_include_directories (mirror_server PRIVATE "${HDF5_UITLS_DIR};${HDF5_SRC_DIR};${HDF5_SRC_BINARY_DIR};$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:${MPI_C_INCLUDE_DIRS}>")
+target_include_directories (mirror_server PRIVATE "${HDF5_UTILS_DIR};${HDF5_SRC_DIR};${HDF5_SRC_BINARY_DIR};$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:${MPI_C_INCLUDE_DIRS}>")
if (NOT BUILD_SHARED_LIBS)
TARGET_C_PROPERTIES (mirror_server STATIC)
target_link_libraries (mirror_server PRIVATE ${HDF5_LIB_TARGET})
@@ -37,7 +37,7 @@ endif ()
set (mirror_server_stop_SOURCES ${HDF5_UTILS_MIRRORVFD_SOURCE_DIR}/mirror_server_stop.c)
add_executable (mirror_server_stop ${mirror_server_stop_SOURCES})
-target_include_directories (mirror_server_stop PRIVATE "${HDF5_UITLS_DIR};${HDF5_SRC_DIR};${HDF5_SRC_BINARY_DIR};$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:${MPI_C_INCLUDE_DIRS}>")
+target_include_directories (mirror_server_stop PRIVATE "${HDF5_UTILS_DIR};${HDF5_SRC_DIR};${HDF5_SRC_BINARY_DIR};$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:${MPI_C_INCLUDE_DIRS}>")
if (NOT BUILD_SHARED_LIBS)
TARGET_C_PROPERTIES (mirror_server_stop STATIC)
target_link_libraries (mirror_server_stop PRIVATE ${HDF5_LIB_TARGET})
diff --git a/utils/mirror_vfd/mirror_server.c b/utils/mirror_vfd/mirror_server.c
index ef41aa5..79c9d80 100644
--- a/utils/mirror_vfd/mirror_server.c
+++ b/utils/mirror_vfd/mirror_server.c
@@ -46,11 +46,8 @@
#ifdef H5_HAVE_MIRROR_VFD
-#define MAXBUF 2048 /* max buffer length. */
-#define LISTENQ 80 /* max pending mirrorS requests */
-#define DEFAULT_PORT 3000 /* default listening port */
-#define MAX_PORT_LOOPS 20 /* max iteratations through port range */
-#define PORT_LOOP_RETRY_DELAY 1 /* seconds to wait between port scans */
+#define LISTENQ 80 /* max pending mirrorS requests */
+#define DEFAULT_PORT 3000 /* default listening port */
/* semi-unique "magic" numbers to sanity-check structure pointers */
#define OP_ARGS_MAGIC 0xCF074379u
@@ -211,8 +208,8 @@ parse_args(int argc, char **argv, struct op_args *args_out)
return -1;
}
- /* Loop over arguments after program name and writer_path */
- for (i = 2; i < argc; i++) {
+ /* Loop over arguments after program name */
+ for (i = 1; i < argc; i++) {
if (!HDstrncmp(argv[i], "-h", 3) || !HDstrncmp(argv[i], "--help", 7)) {
mirror_log(NULL, V_INFO, "found help argument");
args_out->help = 1;
@@ -474,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");
@@ -504,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.
*/
@@ -521,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;
}
@@ -536,17 +543,33 @@ handle_requests(struct server_run *run)
if (!HDstrncmp("SHUTDOWN", mybuf, 8)) {
/* Stop operation if told to stop */
mirror_log(run->loginfo, V_INFO, "received SHUTDOWN!", ret);
+
+ /* Confirm operation */
+ if ((ret = HDwrite(connfd, "CLOSING", 8)) < 0) {
+ mirror_log(run->loginfo, V_ERR, "write:%d", ret);
+ HDclose(connfd);
+ connfd = -1;
+ goto error;
+ }
+
HDclose(connfd);
connfd = -1;
goto done;
} /* end if explicit "SHUTDOWN" directive */
+ if (!HDstrncmp("CONFIRM", mybuf, 7)) {
+ /* Confirm operation */
+ if ((ret = HDwrite(connfd, "ALIVE", 6)) < 0) {
+ mirror_log(run->loginfo, V_ERR, "write:%d", ret);
+ goto error;
+ }
+ 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;
@@ -561,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 {
@@ -591,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() */
diff --git a/utils/mirror_vfd/mirror_server_stop.c b/utils/mirror_vfd/mirror_server_stop.c
index abc4c1e..44386bf 100644
--- a/utils/mirror_vfd/mirror_server_stop.c
+++ b/utils/mirror_vfd/mirror_server_stop.c
@@ -128,6 +128,7 @@ parse_args(int argc, char **argv, struct mshs_opts *opts)
static int
send_shutdown(struct mshs_opts *opts)
{
+ char mybuf[16];
int live_socket;
struct sockaddr_in target_addr;
@@ -157,6 +158,16 @@ send_shutdown(struct mshs_opts *opts)
return -1;
}
+ /* Read & verify response from port connection. */
+ if (HDread(live_socket, &mybuf, sizeof(mybuf)) == -1) {
+ HDprintf("ERROR read() can't receive data\n");
+ return -1;
+ }
+ if (HDstrncmp("CLOSING", mybuf, 8)) {
+ HDprintf("ERROR read() didn't receive data from server\n");
+ return -1;
+ }
+
if (HDclose(live_socket) < 0) {
HDprintf("ERROR close() can't close socket\n");
return -1;
diff --git a/utils/mirror_vfd/mirror_writer.c b/utils/mirror_vfd/mirror_writer.c
index a69ea73..ad7cd91 100644
--- a/utils/mirror_vfd/mirror_writer.c
+++ b/utils/mirror_vfd/mirror_writer.c
@@ -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() */
/* ---------------------------------------------------------------------------