Skip to content

Commit

Permalink
Clean up mirror VFD code in utils dir (HDFGroup#3121)
Browse files Browse the repository at this point in the history
* Remove dead code
* Replace mybzero with memset
* Replace hbool_t/TRUE/FALSE with bool/true/false
  • Loading branch information
derobins authored Jun 14, 2023
1 parent 61d43eb commit 69e8c8f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 82 deletions.
11 changes: 5 additions & 6 deletions utils/mirror_vfd/mirror_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
* [email protected]. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/* Common operations for "remote" processes for the Mirror VFD.
*
* Jacob Smith, 2020-03-06
/*
* Common operations for "remote" processes for the mirror VFD
*/

#include "mirror_remote.h"
Expand All @@ -31,19 +30,19 @@ mirror_log(struct mirror_log_info *info, unsigned int level, const char *format,
{
FILE *stream = MIRROR_LOG_DEFAULT_STREAM;
unsigned int verbosity = MIRROR_LOG_DEFAULT_VERBOSITY;
hbool_t custom = FALSE;
bool custom = false;

if (info != NULL && info->magic == MIRROR_LOG_INFO_MAGIC) {
stream = info->stream;
verbosity = info->verbosity;
custom = TRUE;
custom = true;
}

if (level == V_NONE) {
return;
}
else if (level <= verbosity) {
if (custom == TRUE && info->prefix[0] != '\0') {
if (custom == true && info->prefix[0] != '\0') {
HDfprintf(stream, "%s", info->prefix);
}

Expand Down
5 changes: 2 additions & 3 deletions utils/mirror_vfd/mirror_remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
* [email protected]. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/* Common definitions for "remote" processes for the Mirror VFD.
*
* Jacob Smith, 2020-03-06
/*
* Common definitions for "remote" processes for the mirror VFD
*/

#include "hdf5.h"
Expand Down
37 changes: 7 additions & 30 deletions utils/mirror_vfd/mirror_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,27 +130,6 @@ struct server_run {
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
*
Expand Down Expand Up @@ -190,26 +169,24 @@ usage(void)
static int
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->help = 0;
args_out->log_prepend_serv = 1;
args_out->log_prepend_type = 1;
args_out->verbosity = MIRROR_LOG_DEFAULT_VERBOSITY;
/* preset empty strings */
mybzero(args_out->log_path, PATH_MAX + 1);
mybzero(args_out->writer_log_path, PATH_MAX + 1);

/* Preset empty strings */
HDmemset(args_out->log_path, 0, PATH_MAX + 1);
HDmemset(args_out->writer_log_path, 0, PATH_MAX + 1);

if (argv == NULL || *argv == NULL) {
mirror_log(NULL, V_ERR, "invalid argv pointer");
return -1;
}

/* 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)) {
mirror_log(NULL, V_INFO, "found help argument");
args_out->help = 1;
Expand Down Expand Up @@ -569,7 +546,7 @@ handle_requests(struct server_run *run)
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)) {
if (false == H5FD_mirror_xmit_is_open(xopen)) {
mirror_log(run->loginfo, V_WARN, "expected OPEN xmit was malformed");
HDclose(connfd);
continue;
Expand Down
2 changes: 1 addition & 1 deletion utils/mirror_vfd/mirror_server_stop.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ send_shutdown(struct mshs_opts *opts)
target_addr.sin_family = AF_INET;
target_addr.sin_port = HDhtons((uint16_t)opts->portno);
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) {
HDprintf("ERROR connect() (%d)\n%s\n", errno, HDstrerror(errno));
Expand Down
51 changes: 9 additions & 42 deletions utils/mirror_vfd/mirror_writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,31 +154,8 @@ struct mirror_writer_opts {
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);

/* ---------------------------------------------------------------------------
* 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
*
Expand Down Expand Up @@ -217,10 +194,9 @@ session_init(struct mirror_writer_opts *opts)
session->reply.pub.version = H5FD_MIRROR_XMIT_CURR_VERSION;
session->reply.pub.op = H5FD_MIRROR_OP_REPLY;
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);

Expand Down Expand Up @@ -291,25 +267,16 @@ session_start(int socketfd, const H5FD_mirror_xmit_open_t *xmit_open)
{
struct mirror_session *session = NULL;
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()");

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");
return NULL;
}

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.magic = MW_OPTS_MAGIC;
opts.logpath = NULL;
#endif

session = session_init(&opts);
if (NULL == session) {
Expand Down Expand Up @@ -391,7 +358,7 @@ reply_ok(struct mirror_session *session)
mirror_log(session->loginfo, V_ALL, "reply_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);
} /* end reply_ok() */

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

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()");
reply_error(session, "remote H5FDlock() failure");
return -1;
Expand Down Expand Up @@ -520,7 +487,7 @@ do_open(struct mirror_session *session, const H5FD_mirror_xmit_open_t *xmit_open
haddr_t _maxaddr = HADDR_UNDEF;

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()");

Expand Down Expand Up @@ -664,7 +631,7 @@ do_truncate(struct mirror_session *session)

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) {
mirror_log(session->loginfo, V_ERR, "H5FDtruncate()");
reply_error(session, "remote H5FDtruncate() failure");
Expand Down Expand Up @@ -853,7 +820,7 @@ receive_communique(struct mirror_session *session, struct sock_comm *comm)

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;

mirror_log(session->loginfo, V_INFO, "ready to receive"); /* TODO */
Expand Down

0 comments on commit 69e8c8f

Please sign in to comment.