Clean up mirror VFD code in utils dir (#3121)

* Remove dead code
* Replace mybzero with memset
* Replace hbool_t/TRUE/FALSE with bool/true/false
This commit is contained in:
Dana Robinson 2023-06-14 08:01:04 -07:00 committed by GitHub
parent 61d43eb867
commit 69e8c8f58d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 82 deletions

View File

@ -10,9 +10,8 @@
* help@hdfgroup.org. * * help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* Common operations for "remote" processes for the Mirror VFD. /*
* * Common operations for "remote" processes for the mirror VFD
* Jacob Smith, 2020-03-06
*/ */
#include "mirror_remote.h" #include "mirror_remote.h"
@ -31,19 +30,19 @@ mirror_log(struct mirror_log_info *info, unsigned int level, const char *format,
{ {
FILE *stream = MIRROR_LOG_DEFAULT_STREAM; FILE *stream = MIRROR_LOG_DEFAULT_STREAM;
unsigned int verbosity = MIRROR_LOG_DEFAULT_VERBOSITY; unsigned int verbosity = MIRROR_LOG_DEFAULT_VERBOSITY;
hbool_t custom = FALSE; bool custom = false;
if (info != NULL && info->magic == MIRROR_LOG_INFO_MAGIC) { if (info != NULL && info->magic == MIRROR_LOG_INFO_MAGIC) {
stream = info->stream; stream = info->stream;
verbosity = info->verbosity; verbosity = info->verbosity;
custom = TRUE; custom = true;
} }
if (level == V_NONE) { if (level == V_NONE) {
return; return;
} }
else if (level <= verbosity) { else if (level <= verbosity) {
if (custom == TRUE && info->prefix[0] != '\0') { if (custom == true && info->prefix[0] != '\0') {
HDfprintf(stream, "%s", info->prefix); HDfprintf(stream, "%s", info->prefix);
} }

View File

@ -10,9 +10,8 @@
* help@hdfgroup.org. * * help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* Common definitions for "remote" processes for the Mirror VFD. /*
* * Common definitions for "remote" processes for the mirror VFD
* Jacob Smith, 2020-03-06
*/ */
#include "hdf5.h" #include "hdf5.h"

View File

@ -130,27 +130,6 @@ struct server_run {
int listenfd; int listenfd;
}; };
/* ---------------------------------------------------------------------------
* Function: mybzero
*
* Purpose: Introduce bzero without neededing it on the system.
*
* Programmer: Jacob Smith
* 2020-03-30
* ---------------------------------------------------------------------------
*/
static void
mybzero(void *dest, size_t size)
{
size_t i = 0;
char *s = NULL;
HDassert(dest);
s = (char *)dest;
for (i = 0; i < size; i++) {
*(s + i) = 0;
}
} /* end mybzero() */
/* --------------------------------------------------------------------------- /* ---------------------------------------------------------------------------
* Function: usage * Function: usage
* *
@ -190,18 +169,16 @@ usage(void)
static int static int
parse_args(int argc, char **argv, struct op_args *args_out) parse_args(int argc, char **argv, struct op_args *args_out)
{ {
int i; /* Preset default values */
/* preset default values
*/
args_out->main_port = DEFAULT_PORT; args_out->main_port = DEFAULT_PORT;
args_out->help = 0; args_out->help = 0;
args_out->log_prepend_serv = 1; args_out->log_prepend_serv = 1;
args_out->log_prepend_type = 1; args_out->log_prepend_type = 1;
args_out->verbosity = MIRROR_LOG_DEFAULT_VERBOSITY; args_out->verbosity = MIRROR_LOG_DEFAULT_VERBOSITY;
/* preset empty strings */
mybzero(args_out->log_path, PATH_MAX + 1); /* Preset empty strings */
mybzero(args_out->writer_log_path, PATH_MAX + 1); HDmemset(args_out->log_path, 0, PATH_MAX + 1);
HDmemset(args_out->writer_log_path, 0, PATH_MAX + 1);
if (argv == NULL || *argv == NULL) { if (argv == NULL || *argv == NULL) {
mirror_log(NULL, V_ERR, "invalid argv pointer"); mirror_log(NULL, V_ERR, "invalid argv pointer");
@ -209,7 +186,7 @@ parse_args(int argc, char **argv, struct op_args *args_out)
} }
/* Loop over arguments after program name */ /* Loop over arguments after program name */
for (i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
if (!HDstrncmp(argv[i], "-h", 3) || !HDstrncmp(argv[i], "--help", 7)) { if (!HDstrncmp(argv[i], "-h", 3) || !HDstrncmp(argv[i], "--help", 7)) {
mirror_log(NULL, V_INFO, "found help argument"); mirror_log(NULL, V_INFO, "found help argument");
args_out->help = 1; args_out->help = 1;
@ -569,7 +546,7 @@ handle_requests(struct server_run *run)
mirror_log(run->loginfo, V_INFO, "probable OPEN xmit received"); mirror_log(run->loginfo, V_INFO, "probable OPEN xmit received");
H5FD_mirror_xmit_decode_open(xopen, (const unsigned char *)mybuf); H5FD_mirror_xmit_decode_open(xopen, (const unsigned char *)mybuf);
if (FALSE == H5FD_mirror_xmit_is_open(xopen)) { if (false == H5FD_mirror_xmit_is_open(xopen)) {
mirror_log(run->loginfo, V_WARN, "expected OPEN xmit was malformed"); mirror_log(run->loginfo, V_WARN, "expected OPEN xmit was malformed");
HDclose(connfd); HDclose(connfd);
continue; continue;

View File

@ -146,7 +146,7 @@ send_shutdown(struct mshs_opts *opts)
target_addr.sin_family = AF_INET; target_addr.sin_family = AF_INET;
target_addr.sin_port = HDhtons((uint16_t)opts->portno); target_addr.sin_port = HDhtons((uint16_t)opts->portno);
target_addr.sin_addr.s_addr = HDinet_addr(opts->ip); target_addr.sin_addr.s_addr = HDinet_addr(opts->ip);
HDmemset(target_addr.sin_zero, '\0', sizeof(target_addr.sin_zero)); HDmemset(target_addr.sin_zero, 0, sizeof(target_addr.sin_zero));
if (HDconnect(live_socket, (struct sockaddr *)&target_addr, (socklen_t)sizeof(target_addr)) < 0) { if (HDconnect(live_socket, (struct sockaddr *)&target_addr, (socklen_t)sizeof(target_addr)) < 0) {
HDprintf("ERROR connect() (%d)\n%s\n", errno, HDstrerror(errno)); HDprintf("ERROR connect() (%d)\n%s\n", errno, HDstrerror(errno));

View File

@ -154,31 +154,8 @@ struct mirror_writer_opts {
char *logpath; char *logpath;
}; };
static void mybzero(void *dest, size_t size);
static int do_open(struct mirror_session *session, const H5FD_mirror_xmit_open_t *xmit_open); static int do_open(struct mirror_session *session, const H5FD_mirror_xmit_open_t *xmit_open);
/* ---------------------------------------------------------------------------
* Function: mybzero
*
* Purpose: Introduce bzero without neededing it on the system.
*
* Programmer: Jacob Smith
* 2020-03-30
* ---------------------------------------------------------------------------
*/
static void
mybzero(void *dest, size_t size)
{
size_t i = 0;
char *s = NULL;
HDassert(dest);
s = (char *)dest;
for (i = 0; i < size; i++) {
*(s + i) = 0;
}
} /* end mybzero() */
/* --------------------------------------------------------------------------- /* ---------------------------------------------------------------------------
* Function: session_init * Function: session_init
* *
@ -217,10 +194,9 @@ session_init(struct mirror_writer_opts *opts)
session->reply.pub.version = H5FD_MIRROR_XMIT_CURR_VERSION; session->reply.pub.version = H5FD_MIRROR_XMIT_CURR_VERSION;
session->reply.pub.op = H5FD_MIRROR_OP_REPLY; session->reply.pub.op = H5FD_MIRROR_OP_REPLY;
session->reply.pub.session_token = 0; session->reply.pub.session_token = 0;
mybzero(session->reply.message, H5FD_MIRROR_STATUS_MESSAGE_MAX); HDmemset(session->reply.message, 0, H5FD_MIRROR_STATUS_MESSAGE_MAX);
/* Options-derived population /* Options-derived population */
*/
session->loginfo = mirror_log_init(opts->logpath, "W- ", MIRROR_LOG_DEFAULT_VERBOSITY); session->loginfo = mirror_log_init(opts->logpath, "W- ", MIRROR_LOG_DEFAULT_VERBOSITY);
@ -291,25 +267,16 @@ session_start(int socketfd, const H5FD_mirror_xmit_open_t *xmit_open)
{ {
struct mirror_session *session = NULL; struct mirror_session *session = NULL;
struct mirror_writer_opts opts; struct mirror_writer_opts opts;
#if 0 /* TODO: behavior option */
char logpath[H5FD_MIRROR_XMIT_FILEPATH_MAX] = "";
#endif
mirror_log(NULL, V_INFO, "session_start()"); mirror_log(NULL, V_INFO, "session_start()");
if (FALSE == H5FD_mirror_xmit_is_open(xmit_open)) { if (false == H5FD_mirror_xmit_is_open(xmit_open)) {
mirror_log(NULL, V_ERR, "invalid OPEN xmit"); mirror_log(NULL, V_ERR, "invalid OPEN xmit");
return NULL; return NULL;
} }
opts.magic = MW_OPTS_MAGIC; opts.magic = MW_OPTS_MAGIC;
#if 0 /* TODO: behavior option */
HDsnprintf(logpath, H5FD_MIRROR_XMIT_FILEPATH_MAX, "%s.log",
xmit_open->filename);
opts.logpath = logpath;
#else
opts.logpath = NULL; opts.logpath = NULL;
#endif
session = session_init(&opts); session = session_init(&opts);
if (NULL == session) { if (NULL == session) {
@ -391,7 +358,7 @@ reply_ok(struct mirror_session *session)
mirror_log(session->loginfo, V_ALL, "reply_ok()"); mirror_log(session->loginfo, V_ALL, "reply_ok()");
reply->status = H5FD_MIRROR_STATUS_OK; reply->status = H5FD_MIRROR_STATUS_OK;
mybzero(reply->message, H5FD_MIRROR_STATUS_MESSAGE_MAX); HDmemset(reply->message, 0, H5FD_MIRROR_STATUS_MESSAGE_MAX);
return _xmit_reply(session); return _xmit_reply(session);
} /* end reply_ok() */ } /* end reply_ok() */
@ -489,7 +456,7 @@ do_lock(struct mirror_session *session, const unsigned char *xmit_buf)
} }
mirror_log(session->loginfo, V_INFO, "lock rw: (%d)", xmit_lock.rw); mirror_log(session->loginfo, V_INFO, "lock rw: (%d)", xmit_lock.rw);
if (H5FDlock(session->file, (hbool_t)xmit_lock.rw) < 0) { if (H5FDlock(session->file, (bool)xmit_lock.rw) < 0) {
mirror_log(session->loginfo, V_ERR, "H5FDlock()"); mirror_log(session->loginfo, V_ERR, "H5FDlock()");
reply_error(session, "remote H5FDlock() failure"); reply_error(session, "remote H5FDlock() failure");
return -1; return -1;
@ -520,7 +487,7 @@ do_open(struct mirror_session *session, const H5FD_mirror_xmit_open_t *xmit_open
haddr_t _maxaddr = HADDR_UNDEF; haddr_t _maxaddr = HADDR_UNDEF;
HDassert(session && (session->magic == MW_SESSION_MAGIC) && xmit_open && HDassert(session && (session->magic == MW_SESSION_MAGIC) && xmit_open &&
TRUE == H5FD_mirror_xmit_is_open(xmit_open)); true == H5FD_mirror_xmit_is_open(xmit_open));
mirror_log(session->loginfo, V_INFO, "do_open()"); mirror_log(session->loginfo, V_INFO, "do_open()");
@ -664,7 +631,7 @@ do_truncate(struct mirror_session *session)
mirror_log(session->loginfo, V_INFO, "do_truncate()"); mirror_log(session->loginfo, V_INFO, "do_truncate()");
/* default DXPL ID (0), 0 for "FALSE" closing -- both probably unused */ /* default DXPL ID (0), 0 for "false" closing -- both probably unused */
if (H5FDtruncate(session->file, 0, 0) < 0) { if (H5FDtruncate(session->file, 0, 0) < 0) {
mirror_log(session->loginfo, V_ERR, "H5FDtruncate()"); mirror_log(session->loginfo, V_ERR, "H5FDtruncate()");
reply_error(session, "remote H5FDtruncate() failure"); reply_error(session, "remote H5FDtruncate() failure");
@ -853,7 +820,7 @@ receive_communique(struct mirror_session *session, struct sock_comm *comm)
mirror_log(session->loginfo, V_INFO, "receive_communique()"); mirror_log(session->loginfo, V_INFO, "receive_communique()");
mybzero(comm->raw, comm->raw_size); HDmemset(comm->raw, 0, comm->raw_size);
comm->recd_die = 0; comm->recd_die = 0;
mirror_log(session->loginfo, V_INFO, "ready to receive"); /* TODO */ mirror_log(session->loginfo, V_INFO, "ready to receive"); /* TODO */