summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/mirror_vfd/mirror_remote.c82
-rw-r--r--utils/mirror_vfd/mirror_remote.h23
-rw-r--r--utils/mirror_vfd/mirror_server.c197
-rw-r--r--utils/mirror_vfd/mirror_server_stop.c66
-rw-r--r--utils/mirror_vfd/mirror_writer.c314
5 files changed, 283 insertions, 399 deletions
diff --git a/utils/mirror_vfd/mirror_remote.c b/utils/mirror_vfd/mirror_remote.c
index 81a3625..4e538ee 100644
--- a/utils/mirror_vfd/mirror_remote.c
+++ b/utils/mirror_vfd/mirror_remote.c
@@ -19,7 +19,6 @@
#ifdef H5_HAVE_MIRROR_VFD
-
/* ---------------------------------------------------------------------------
* Function: mirror_log
*
@@ -28,39 +27,35 @@
* ----------------------------------------------------------------------------
*/
void
-mirror_log(struct mirror_log_info *info,
- unsigned int level,
- const char *format,
- ...)
+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;
- hbool_t custom = FALSE;
+ hbool_t custom = FALSE;
if (info != NULL && info->magic == MIRROR_LOG_INFO_MAGIC) {
- stream = info->stream;
+ stream = info->stream;
verbosity = info->verbosity;
- custom = TRUE;
+ custom = TRUE;
}
if (level == V_NONE) {
return;
}
- else
- if (level <= verbosity) {
+ else if (level <= verbosity) {
if (custom == TRUE && info->prefix[0] != '\0') {
HDfprintf(stream, "%s", info->prefix);
}
switch (level) {
- case (V_ERR) :
- HDfprintf(stream, "ERROR ");
- break;
- case (V_WARN) :
- HDfprintf(stream, "WARNING ");
- break;
- default:
- break;
+ case (V_ERR):
+ HDfprintf(stream, "ERROR ");
+ break;
+ case (V_WARN):
+ HDfprintf(stream, "WARNING ");
+ break;
+ default:
+ break;
}
if (format != NULL) {
@@ -75,7 +70,6 @@ mirror_log(struct mirror_log_info *info,
} /* end if sufficiently verbose to print */
} /* end mirror_log() */
-
/* ---------------------------------------------------------------------------
* Function: session_log_bytes
*
@@ -84,12 +78,9 @@ mirror_log(struct mirror_log_info *info,
* ----------------------------------------------------------------------------
*/
void
-mirror_log_bytes(struct mirror_log_info *info,
- unsigned int level,
- size_t n_bytes,
- const unsigned char *buf)
+mirror_log_bytes(struct mirror_log_info *info, unsigned int level, size_t n_bytes, const unsigned char *buf)
{
- FILE *stream = MIRROR_LOG_DEFAULT_STREAM;
+ FILE * stream = MIRROR_LOG_DEFAULT_STREAM;
unsigned int verbosity = MIRROR_LOG_DEFAULT_VERBOSITY;
if (buf == NULL) {
@@ -97,27 +88,25 @@ mirror_log_bytes(struct mirror_log_info *info,
}
if (info != NULL && info->magic == MIRROR_LOG_INFO_MAGIC) {
- stream = info->stream;
+ stream = info->stream;
verbosity = info->verbosity;
}
if (level <= verbosity) {
- size_t bytes_written = 0;
- const unsigned char *b = NULL;
+ size_t bytes_written = 0;
+ const unsigned char *b = NULL;
/* print whole lines */
while ((n_bytes - bytes_written) >= 32) {
b = buf + bytes_written; /* point to region in buffer */
HDfprintf(stream,
- "%04zX %02X%02X%02X%02X %02X%02X%02X%02X" \
- " %02X%02X%02X%02X %02X%02X%02X%02X" \
- " %02X%02X%02X%02X %02X%02X%02X%02X" \
- " %02X%02X%02X%02X %02X%02X%02X%02X\n",
- bytes_written,
- b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7],
- b[8], b[9], b[10],b[11], b[12],b[13],b[14],b[15],
- b[16],b[17],b[18],b[19], b[20],b[21],b[22],b[23],
- b[24],b[25],b[26],b[27], b[28],b[29],b[30],b[31]);
+ "%04zX %02X%02X%02X%02X %02X%02X%02X%02X"
+ " %02X%02X%02X%02X %02X%02X%02X%02X"
+ " %02X%02X%02X%02X %02X%02X%02X%02X"
+ " %02X%02X%02X%02X %02X%02X%02X%02X\n",
+ bytes_written, b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11],
+ b[12], b[13], b[14], b[15], b[16], b[17], b[18], b[19], b[20], b[21], b[22], b[23],
+ b[24], b[25], b[26], b[27], b[28], b[29], b[30], b[31]);
bytes_written += 32;
}
@@ -128,9 +117,8 @@ mirror_log_bytes(struct mirror_log_info *info,
/* partial line blocks */
while ((n_bytes - bytes_written) >= 4) {
- HDfprintf(stream, " %02X%02X%02X%02X",
- buf[bytes_written], buf[bytes_written+1],
- buf[bytes_written+2], buf[bytes_written+3]);
+ HDfprintf(stream, " %02X%02X%02X%02X", buf[bytes_written], buf[bytes_written + 1],
+ buf[bytes_written + 2], buf[bytes_written + 3]);
bytes_written += 4;
}
@@ -149,7 +137,6 @@ mirror_log_bytes(struct mirror_log_info *info,
} /* end if suitably verbose to log */
} /* end mirror_log_bytes() */
-
/* ---------------------------------------------------------------------------
* Function: mirror_log_init
*
@@ -166,9 +153,9 @@ mirror_log_init(char *path, char *prefix, unsigned int verbosity)
info = (loginfo_t *)HDmalloc(sizeof(loginfo_t));
if (info != NULL) {
- info->magic = MIRROR_LOG_INFO_MAGIC;
+ info->magic = MIRROR_LOG_INFO_MAGIC;
info->verbosity = verbosity;
- info->stream = MIRROR_LOG_DEFAULT_STREAM;
+ info->stream = MIRROR_LOG_DEFAULT_STREAM;
info->prefix[0] = '\0';
if (prefix && *prefix) {
@@ -177,11 +164,10 @@ mirror_log_init(char *path, char *prefix, unsigned int verbosity)
if (path && *path) {
FILE *f = NULL;
- f = HDfopen(path, "w");
+ f = HDfopen(path, "w");
if (NULL == f) {
- HDfprintf(MIRROR_LOG_DEFAULT_STREAM,
- "WARN custom logging path could not be opened: %s\n",
- path);
+ HDfprintf(MIRROR_LOG_DEFAULT_STREAM, "WARN custom logging path could not be opened: %s\n",
+ path);
info->magic += 1;
HDfree(info);
}
@@ -195,7 +181,6 @@ mirror_log_init(char *path, char *prefix, unsigned int verbosity)
return info;
} /* end mirror_log_init() */
-
/* ---------------------------------------------------------------------------
* Function: mirror_log_term
*
@@ -222,4 +207,3 @@ mirror_log_term(loginfo_t *info)
} /* end mirror_log_term() */
#endif /* H5_HAVE_MIRROR_VFD */
-
diff --git a/utils/mirror_vfd/mirror_remote.h b/utils/mirror_vfd/mirror_remote.h
index 67e95a5..6256d1b 100644
--- a/utils/mirror_vfd/mirror_remote.h
+++ b/utils/mirror_vfd/mirror_remote.h
@@ -20,7 +20,7 @@
#ifdef H5_HAVE_MIRROR_VFD
-#include "H5FDmirror_priv.h" /* Private header for the mirror VFD */
+#include "H5FDmirror_priv.h" /* Private header for the mirror VFD */
#define V_NONE 0
#define V_ERR 1
@@ -28,26 +28,23 @@
#define V_INFO 3
#define V_ALL 4
-#define MIRROR_LOG_DEFAULT_STREAM stdout
+#define MIRROR_LOG_DEFAULT_STREAM stdout
#define MIRROR_LOG_DEFAULT_VERBOSITY V_WARN
-#define MIRROR_LOG_PREFIX_MAX 79
-#define MIRROR_LOG_INFO_MAGIC 0x569D589A
+#define MIRROR_LOG_PREFIX_MAX 79
+#define MIRROR_LOG_INFO_MAGIC 0x569D589A
typedef struct mirror_log_info {
- uint32_t magic;
- FILE *stream;
+ uint32_t magic;
+ FILE * stream;
unsigned int verbosity;
- char prefix[MIRROR_LOG_PREFIX_MAX+1];
+ char prefix[MIRROR_LOG_PREFIX_MAX + 1];
} loginfo_t;
-void mirror_log(loginfo_t *info, unsigned int level,
- const char *format, ...);
-void mirror_log_bytes(loginfo_t *info, unsigned int level,
- size_t n_bytes, const unsigned char *buf);
+void mirror_log(loginfo_t *info, unsigned int level, const char *format, ...);
+void mirror_log_bytes(loginfo_t *info, unsigned int level, size_t n_bytes, const unsigned char *buf);
loginfo_t *mirror_log_init(char *path, char *prefix, unsigned int verbosity);
-int mirror_log_term(loginfo_t *loginfo);
+int mirror_log_term(loginfo_t *loginfo);
herr_t run_writer(int socketfd, H5FD_mirror_xmit_open_t *xmit_open);
#endif /* H5_HAVE_MIRROR_VFD */
-
diff --git a/utils/mirror_vfd/mirror_server.c b/utils/mirror_vfd/mirror_server.c
index db7cf04..9990969 100644
--- a/utils/mirror_vfd/mirror_server.c
+++ b/utils/mirror_vfd/mirror_server.c
@@ -46,17 +46,16 @@
#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 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 */
/* semi-unique "magic" numbers to sanity-check structure pointers */
#define OP_ARGS_MAGIC 0xCF074379u
#define SERVER_RUN_MAGIC 0x741B459Au
-
/* ---------------------------------------------------------------------------
* Structure: struct op_args
*
@@ -95,17 +94,16 @@
* ---------------------------------------------------------------------------
*/
struct op_args {
- uint32_t magic;
- int help;
- int main_port;
- int verbosity;
- int log_prepend_serv;
- int log_prepend_type;
- char log_path[PATH_MAX+1];
- char writer_log_path[PATH_MAX+1];
+ uint32_t magic;
+ int help;
+ int main_port;
+ int verbosity;
+ int log_prepend_serv;
+ int log_prepend_type;
+ char log_path[PATH_MAX + 1];
+ char writer_log_path[PATH_MAX + 1];
};
-
/* ---------------------------------------------------------------------------
* Structure: struct server_run
*
@@ -129,13 +127,12 @@ struct op_args {
* ---------------------------------------------------------------------------
*/
struct server_run {
- uint32_t magic;
- struct op_args opts;
+ uint32_t magic;
+ struct op_args opts;
struct mirror_log_info *loginfo;
- int listenfd;
+ int listenfd;
};
-
/* ---------------------------------------------------------------------------
* Function: mybzero
*
@@ -145,18 +142,18 @@ struct server_run {
* 2020-03-30
* ---------------------------------------------------------------------------
*/
-static void mybzero(void *dest, size_t size)
+static void
+mybzero(void *dest, size_t size)
{
size_t i = 0;
- char *s = NULL;
+ char * s = NULL;
HDassert(dest);
s = (char *)dest;
for (i = 0; i < size; i++) {
- *(s+i) = 0;
+ *(s + i) = 0;
}
} /* end mybzero() */
-
/* ---------------------------------------------------------------------------
* Function: usage
*
@@ -167,25 +164,23 @@ static void
usage(void)
{
HDfprintf(stdout,
- "mirror_server [options]\n" \
- "\n" \
- "Application for providing Mirror Writer process to " \
- " Mirror VFD on file-open.\n" \
- "Listens on a dedicated socket; forks as a Writer upon receipt" \
- " of a valid OPEN xmit.\n" \
- "\n" \
- "Options:\n" \
- "--help [-h] : Print this help message and quit.\n" \
- "--logpath=PATH : File path for logging output " \
- "(default none, to stdout).\n" \
- "--port=PORT : Primary port (default %d).\n" \
- "--verbosity=NUM : Debug printing level " \
- "0..4, (default %d).\n",
- DEFAULT_PORT,
- MIRROR_LOG_DEFAULT_VERBOSITY);
+ "mirror_server [options]\n"
+ "\n"
+ "Application for providing Mirror Writer process to "
+ " Mirror VFD on file-open.\n"
+ "Listens on a dedicated socket; forks as a Writer upon receipt"
+ " of a valid OPEN xmit.\n"
+ "\n"
+ "Options:\n"
+ "--help [-h] : Print this help message and quit.\n"
+ "--logpath=PATH : File path for logging output "
+ "(default none, to stdout).\n"
+ "--port=PORT : Primary port (default %d).\n"
+ "--verbosity=NUM : Debug printing level "
+ "0..4, (default %d).\n",
+ DEFAULT_PORT, MIRROR_LOG_DEFAULT_VERBOSITY);
} /* end usage() */
-
/* ---------------------------------------------------------------------------
* Function: parse_args
*
@@ -202,14 +197,14 @@ parse_args(int argc, char **argv, struct op_args *args_out)
/* preset default values
*/
- args_out->main_port = DEFAULT_PORT;
- args_out->help = 0;
+ 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;
+ 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);
+ mybzero(args_out->log_path, PATH_MAX + 1);
+ mybzero(args_out->writer_log_path, PATH_MAX + 1);
if (argv == NULL || *argv == NULL) {
mirror_log(NULL, V_ERR, "invalid argv pointer");
@@ -217,39 +212,35 @@ parse_args(int argc, char **argv, struct op_args *args_out)
}
/* Loop over arguments after program name and writer_path */
- for (i=2; i < argc; i++) {
+ for (i = 2; 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;
return 0;
} /* end if help */
- else
- if (!HDstrncmp(argv[i], "--port=", 7)) {
- mirror_log(NULL, V_INFO, "parsing 'main_port' (%s)", argv[i]+7);
- args_out->main_port = HDatoi(argv[i]+7);
+ else if (!HDstrncmp(argv[i], "--port=", 7)) {
+ mirror_log(NULL, V_INFO, "parsing 'main_port' (%s)", argv[i] + 7);
+ args_out->main_port = HDatoi(argv[i] + 7);
} /* end if port */
- else
- if (!HDstrncmp(argv[i], "--verbosity=", 12)) {
- mirror_log(NULL, V_INFO, "parsing 'verbosity' (%s)", argv[i]+12);
- args_out->verbosity = HDatoi(argv[i]+12);
+ else if (!HDstrncmp(argv[i], "--verbosity=", 12)) {
+ mirror_log(NULL, V_INFO, "parsing 'verbosity' (%s)", argv[i] + 12);
+ args_out->verbosity = HDatoi(argv[i] + 12);
} /* end if verbosity */
- else
- if (!HDstrncmp(argv[i], "--logpath=", 10)) {
- mirror_log(NULL, V_INFO, "parsing 'logpath' (%s)", argv[i]+10);
- HDstrncpy(args_out->log_path, argv[i]+10, PATH_MAX);
+ else if (!HDstrncmp(argv[i], "--logpath=", 10)) {
+ mirror_log(NULL, V_INFO, "parsing 'logpath' (%s)", argv[i] + 10);
+ HDstrncpy(args_out->log_path, argv[i] + 10, PATH_MAX);
} /* end if logpath */
else {
mirror_log(NULL, V_ERR, "unrecognized argument: %s", argv[i]);
return -1;
} /* end if unrecognized argument */
- } /* end for each arg after the path to writer "receiver process" */
+ } /* end for each arg after the path to writer "receiver process" */
mirror_log(NULL, V_INFO, "all args parsed");
return 0;
} /* end parse_args() */
-
/* ---------------------------------------------------------------------------
* Function: prepare_listening_socket
*
@@ -264,9 +255,9 @@ static int
prepare_listening_socket(struct server_run *run)
{
struct sockaddr_in server_addr;
- int _true = 1; /* needed for setsockopt() */
- int ret_value = -1;
- int ret = 0; /* for checking return value of function calls */
+ int _true = 1; /* needed for setsockopt() */
+ int ret_value = -1;
+ int ret = 0; /* for checking return value of function calls */
if (run == NULL || run->magic != SERVER_RUN_MAGIC) {
mirror_log(NULL, V_ERR, "invalid server_run pointer");
@@ -290,8 +281,7 @@ prepare_listening_socket(struct server_run *run)
HDsetsockopt(ret_value, SOL_SOCKET, SO_REUSEADDR, &_true, sizeof(int));
mirror_log(run->loginfo, V_INFO, "bind()");
- ret = HDbind(ret_value, (struct sockaddr *)&server_addr,
- sizeof(server_addr));
+ ret = HDbind(ret_value, (struct sockaddr *)&server_addr, sizeof(server_addr));
if (ret < 0) {
mirror_log(run->loginfo, V_ERR, "bind() %s", HDstrerror(errno));
goto error;
@@ -314,7 +304,6 @@ error:
return -1;
} /* end prepare_listening_socket() */
-
/* ---------------------------------------------------------------------------
* Function: init_server_run
*
@@ -334,9 +323,9 @@ init_server_run(int argc, char **argv)
return NULL;
}
- run->magic = (uint32_t)SERVER_RUN_MAGIC;
+ run->magic = (uint32_t)SERVER_RUN_MAGIC;
run->opts.magic = (uint32_t)OP_ARGS_MAGIC;
- run->listenfd = -1;
+ run->listenfd = -1;
if (parse_args(argc, argv, &(run->opts)) < 0) {
mirror_log(NULL, V_ERR, "can't parse arguments");
@@ -349,8 +338,7 @@ init_server_run(int argc, char **argv)
return run; /* early exit */
}
- run->loginfo = mirror_log_init(run->opts.log_path, "s- ",
- run->opts.verbosity);
+ run->loginfo = mirror_log_init(run->opts.log_path, "s- ", run->opts.verbosity);
run->listenfd = prepare_listening_socket(run);
if (run->listenfd < 0) {
@@ -368,7 +356,6 @@ error:
} /* end init_server_run() */
-
/* ---------------------------------------------------------------------------
* Function: term_server_run
*
@@ -389,7 +376,7 @@ term_server_run(struct server_run *run)
if (run->listenfd >= 0) {
HDshutdown(run->listenfd, SHUT_RDWR); /* TODO: error-checking? */
- HDclose(run->listenfd); /* TODO: error-checking? */
+ HDclose(run->listenfd); /* TODO: error-checking? */
run->listenfd = -1;
}
@@ -405,7 +392,6 @@ term_server_run(struct server_run *run)
return 0;
} /* end term_server_run() */
-
/* ---------------------------------------------------------------------------
* Function: accept_connection
*
@@ -418,11 +404,11 @@ term_server_run(struct server_run *run)
static int
accept_connection(struct server_run *run)
{
- struct sockaddr_in client_addr; /**/
- socklen_t clilen; /**/
- struct hostent *host_port = NULL; /**/
- char *hostaddrp; /**/
- int connfd = -1; /* connection file descriptor */
+ struct sockaddr_in client_addr; /**/
+ socklen_t clilen; /**/
+ struct hostent * host_port = NULL; /**/
+ char * hostaddrp; /**/
+ int connfd = -1; /* connection file descriptor */
if (run == NULL || run->magic != SERVER_RUN_MAGIC) {
mirror_log(NULL, V_ERR, "invalid server_run pointer");
@@ -441,10 +427,8 @@ accept_connection(struct server_run *run)
/*------------------------------*/
/* get client address information */
- host_port = HDgethostbyaddr(
- (const char *)&client_addr.sin_addr.s_addr,
- sizeof(client_addr.sin_addr.s_addr),
- AF_INET);
+ host_port = HDgethostbyaddr((const char *)&client_addr.sin_addr.s_addr,
+ sizeof(client_addr.sin_addr.s_addr), AF_INET);
if (host_port == NULL) {
mirror_log(run->loginfo, V_ERR, "gethostbyaddr()");
goto error;
@@ -454,10 +438,7 @@ accept_connection(struct server_run *run)
hostaddrp = HDinet_ntoa(client_addr.sin_addr);
/* TODO? proper error-checking */
- mirror_log(run->loginfo, V_INFO,
- "server connected with %s (%s)",
- host_port->h_name,
- hostaddrp);
+ mirror_log(run->loginfo, V_INFO, "server connected with %s (%s)", host_port->h_name, hostaddrp);
return connfd;
@@ -468,7 +449,6 @@ error:
return -1;
} /* end accept_connection() */
-
/* ---------------------------------------------------------------------------
* Function: wait_for_child
*
@@ -478,10 +458,10 @@ error:
static void
wait_for_child(int sig)
{
- while (HDwaitpid(-1, NULL, WNOHANG) > 0);
+ while (HDwaitpid(-1, NULL, WNOHANG) > 0)
+ ;
} /* end wait_for_child() */
-
/* ---------------------------------------------------------------------------
* Function: handle_requests
*
@@ -494,12 +474,12 @@ wait_for_child(int sig)
static int
handle_requests(struct server_run *run)
{
- int connfd = -1; /**/
- char mybuf[H5FD_MIRROR_XMIT_OPEN_SIZE]; /**/
- int ret; /* general-purpose error-checking */
- int pid; /* process ID of fork */
+ int connfd = -1; /**/
+ char mybuf[H5FD_MIRROR_XMIT_OPEN_SIZE]; /**/
+ int ret; /* general-purpose error-checking */
+ int pid; /* process ID of fork */
struct sigaction sa;
- int ret_value = 0;
+ int ret_value = 0;
if (run == NULL || run->magic != SERVER_RUN_MAGIC) {
mirror_log(NULL, V_ERR, "invalid server_run pointer");
@@ -548,8 +528,7 @@ handle_requests(struct server_run *run)
}
mirror_log(run->loginfo, V_INFO, "received %d bytes", ret);
mirror_log(run->loginfo, V_ALL, "```");
- mirror_log_bytes(run->loginfo, V_ALL, ret,
- (const unsigned char *)mybuf);
+ mirror_log_bytes(run->loginfo, V_ALL, ret, (const unsigned char *)mybuf);
mirror_log(run->loginfo, V_ALL, "```");
/* Respond to handshake message.
@@ -562,33 +541,27 @@ handle_requests(struct server_run *run)
connfd = -1;
goto done;
} /* end if explicit "SHUTDOWN" directive */
- else
- if (H5FD_MIRROR_XMIT_OPEN_SIZE == ret) {
+ else if (H5FD_MIRROR_XMIT_OPEN_SIZE == ret) {
H5FD_mirror_xmit_open_t xopen;
- 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);
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);
continue;
}
- mirror_log(run->loginfo, V_INFO,
- "probable OPEN xmit confirmed");
+ mirror_log(run->loginfo, V_INFO, "probable OPEN xmit confirmed");
pid = HDfork();
if (pid < 0) { /* fork error */
mirror_log(run->loginfo, V_ERR, "cannot fork");
goto error;
- } /* end if fork error */
- else
- if (pid == 0) { /* child process (writer side of fork) */
- mirror_log(run->loginfo, V_INFO,
- "executing writer");
+ } /* 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) {
HDprintf("can't run writer\n");
}
@@ -598,7 +571,7 @@ handle_requests(struct server_run *run)
HDclose(connfd);
HDexit(EXIT_SUCCESS);
- } /* end if writer side of fork */
+ } /* end if writer side of fork */
else { /* parent process (server side of fork) */
mirror_log(run->loginfo, V_INFO, "tidying up from handshake");
HDclose(connfd);
@@ -628,12 +601,11 @@ error:
return -1;
} /* end handle_requests() */
-
/* ------------------------------------------------------------------------- */
int
main(int argc, char **argv)
{
- struct server_run *run;
+ struct server_run *run;
run = init_server_run(argc, argv);
if (NULL == run) {
@@ -663,4 +635,3 @@ main(void)
}
#endif /* H5_HAVE_MIRROR_VFD */
-
diff --git a/utils/mirror_vfd/mirror_server_stop.c b/utils/mirror_vfd/mirror_server_stop.c
index f2414e0..9a1ff0a 100644
--- a/utils/mirror_vfd/mirror_server_stop.c
+++ b/utils/mirror_vfd/mirror_server_stop.c
@@ -19,12 +19,11 @@
#ifdef H5_HAVE_MIRROR_VFD
-#define MSHS_OPTS_MAGIC 0x613B1C15u /* sanity-checking constant */
-#define MSHS_IP_STR_SIZE 20
-#define MSHS_DEFAULT_IP "127.0.0.1"
+#define MSHS_OPTS_MAGIC 0x613B1C15u /* sanity-checking constant */
+#define MSHS_IP_STR_SIZE 20
+#define MSHS_DEFAULT_IP "127.0.0.1"
#define MSHS_DEFAULT_PORTNO 3000
-
/* ----------------------------------------------------------------------------
* Structure: struct mshs_opts
*
@@ -46,13 +45,12 @@
* ----------------------------------------------------------------------------
*/
struct mshs_opts {
- uint32_t magic;
- int help;
- int portno;
- char ip[MSHS_IP_STR_SIZE + 1];
+ uint32_t magic;
+ int help;
+ int portno;
+ char ip[MSHS_IP_STR_SIZE + 1];
};
-
/* ----------------------------------------------------------------------------
* Function: usage
*
@@ -62,19 +60,17 @@ struct mshs_opts {
static void
usage(void)
{
- HDprintf("mirror_server_halten_sie [options]\n" \
- "System-independent Mirror Server shutdown program.\n" \
- "Sends shutdown message to Mirror Server at given IP:port\n" \
- "\n" \
- "Options:\n" \
- " -h | --help Print this usage message and exit.\n" \
- " --ip=ADDR IP Address of remote server (defaut %s)\n" \
+ HDprintf("mirror_server_halten_sie [options]\n"
+ "System-independent Mirror Server shutdown program.\n"
+ "Sends shutdown message to Mirror Server at given IP:port\n"
+ "\n"
+ "Options:\n"
+ " -h | --help Print this usage message and exit.\n"
+ " --ip=ADDR IP Address of remote server (defaut %s)\n"
" --port=PORT Handshake port of remote server (default %d)\n",
- MSHS_DEFAULT_IP,
- MSHS_DEFAULT_PORTNO);
+ MSHS_DEFAULT_IP, MSHS_DEFAULT_PORTNO);
} /* end usage() */
-
/* ----------------------------------------------------------------------------
* Function: parse_args
*
@@ -90,22 +86,20 @@ parse_args(int argc, char **argv, struct mshs_opts *opts)
{
int i = 0;
- opts->magic = MSHS_OPTS_MAGIC;
- opts->help = 0;
+ opts->magic = MSHS_OPTS_MAGIC;
+ opts->help = 0;
opts->portno = MSHS_DEFAULT_PORTNO;
HDstrncpy(opts->ip, MSHS_DEFAULT_IP, MSHS_IP_STR_SIZE);
- for (i=1; i < argc; i++) { /* start with first possible option argument */
+ for (i = 1; i < argc; i++) { /* start with first possible option argument */
if (!HDstrncmp(argv[i], "-h", 3) || !HDstrncmp(argv[i], "--help", 7)) {
opts->help = 1;
}
- else
- if (!HDstrncmp(argv[i], "--ip=", 5)) {
- HDstrncpy(opts->ip, argv[i]+5, MSHS_IP_STR_SIZE);
+ else if (!HDstrncmp(argv[i], "--ip=", 5)) {
+ HDstrncpy(opts->ip, argv[i] + 5, MSHS_IP_STR_SIZE);
}
- else
- if (!HDstrncmp(argv[i], "--port=", 7)) {
- opts->portno = HDatoi(argv[i]+7);
+ else if (!HDstrncmp(argv[i], "--port=", 7)) {
+ opts->portno = HDatoi(argv[i] + 7);
}
else {
HDprintf("Unrecognized option: '%s'\n", argv[i]);
@@ -123,7 +117,6 @@ parse_args(int argc, char **argv, struct mshs_opts *opts)
return 0;
} /* end parse_args() */
-
/* ----------------------------------------------------------------------------
* Function: send_shutdown
*
@@ -139,8 +132,8 @@ send_shutdown(struct mshs_opts *opts)
struct sockaddr_in target_addr;
if (opts->magic != MSHS_OPTS_MAGIC) {
- HDprintf("invalid options structure\n");
- return -1;
+ HDprintf("invalid options structure\n");
+ return -1;
}
live_socket = HDsocket(AF_INET, SOCK_STREAM, 0);
@@ -149,15 +142,12 @@ send_shutdown(struct mshs_opts *opts)
return -1;
}
- target_addr.sin_family = AF_INET;
- target_addr.sin_port = HDhtons((uint16_t)opts->portno);
+ 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));
- 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));
return -1;
}
@@ -175,7 +165,6 @@ send_shutdown(struct mshs_opts *opts)
return 0;
} /* end send_shutdown() */
-
/* ------------------------------------------------------------------------- */
int
main(int argc, char **argv)
@@ -202,7 +191,6 @@ main(int argc, char **argv)
#else /* H5_HAVE_MIRROR_VFD */
-
/* ------------------------------------------------------------------------- */
int
main(void)
diff --git a/utils/mirror_vfd/mirror_writer.c b/utils/mirror_vfd/mirror_writer.c
index e1ab1b2..d8da7fd 100644
--- a/utils/mirror_vfd/mirror_writer.c
+++ b/utils/mirror_vfd/mirror_writer.c
@@ -25,17 +25,16 @@
#ifdef H5_HAVE_MIRROR_VFD
-#define HEXDUMP_XMITS 1 /* Toggle whether to print xmit bytes-blob */
- /* in detailed logging */
-#define HEXDUMP_WRITEDATA 0 /* Toggle whether to print bytes to write */
- /* in detailed logging */
-#define LISTENQ 80 /* max pending Driver requests */
+#define HEXDUMP_XMITS 1 /* Toggle whether to print xmit bytes-blob */
+ /* in detailed logging */
+#define HEXDUMP_WRITEDATA 0 /* Toggle whether to print bytes to write */
+ /* in detailed logging */
+#define LISTENQ 80 /* max pending Driver requests */
-#define MW_SESSION_MAGIC 0x88F36B32u
-#define MW_SOCK_COMM_MAGIC 0xDF10A157u
-#define MW_OPTS_MAGIC 0x3BA8B462u
+#define MW_SESSION_MAGIC 0x88F36B32u
+#define MW_SOCK_COMM_MAGIC 0xDF10A157u
+#define MW_OPTS_MAGIC 0x3BA8B462u
-
/* ---------------------------------------------------------------------------
* Structure: struct mirror_session
*
@@ -85,16 +84,15 @@
* ----------------------------------------------------------------------------
*/
struct mirror_session {
- uint32_t magic;
- int sockfd;
- uint32_t token;
- uint32_t xmit_count;
- H5FD_t *file;
- loginfo_t *loginfo;
- H5FD_mirror_xmit_reply_t reply;
+ uint32_t magic;
+ int sockfd;
+ uint32_t token;
+ uint32_t xmit_count;
+ H5FD_t * file;
+ loginfo_t * loginfo;
+ H5FD_mirror_xmit_reply_t reply;
};
-
/* ---------------------------------------------------------------------------
* Structure: struct sock_comm
*
@@ -129,11 +127,10 @@ struct sock_comm {
uint32_t magic;
int recd_die;
H5FD_mirror_xmit_t *xmit_recd;
- char *raw;
+ char * raw;
size_t raw_size;
};
-
/* ---------------------------------------------------------------------------
* Structure: struct mirror_writer_opts
*
@@ -153,16 +150,14 @@ struct sock_comm {
* ----------------------------------------------------------------------------
*/
struct mirror_writer_opts {
- uint32_t magic;
- char *logpath;
+ uint32_t magic;
+ 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
*
@@ -172,18 +167,18 @@ static int do_open(struct mirror_session *session,
* 2020-03-30
* ---------------------------------------------------------------------------
*/
-static void mybzero(void *dest, size_t size)
+static void
+mybzero(void *dest, size_t size)
{
size_t i = 0;
- char *s = NULL;
+ char * s = NULL;
HDassert(dest);
s = (char *)dest;
for (i = 0; i < size; i++) {
- *(s+i) = 0;
+ *(s + i) = 0;
}
} /* end mybzero() */
-
/* ---------------------------------------------------------------------------
* Function: session_init
*
@@ -212,11 +207,11 @@ session_init(struct mirror_writer_opts *opts)
goto error;
}
- session->magic = MW_SESSION_MAGIC;
- session->sockfd = -1;
- session->xmit_count = 0;
- session->token = 0;
- session->file = NULL;
+ session->magic = MW_SESSION_MAGIC;
+ session->sockfd = -1;
+ session->xmit_count = 0;
+ session->token = 0;
+ session->file = NULL;
session->reply.pub.magic = H5FD_MIRROR_XMIT_MAGIC;
session->reply.pub.version = H5FD_MIRROR_XMIT_CURR_VERSION;
@@ -227,8 +222,7 @@ session_init(struct mirror_writer_opts *opts)
/* 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);
return session;
@@ -239,7 +233,6 @@ error:
return NULL;
} /* end session_init() */
-
/* ---------------------------------------------------------------------------
* Function: session_stop
*
@@ -283,7 +276,6 @@ session_stop(struct mirror_session *session)
return ret_value;
} /* end session_stop() */
-
/* ---------------------------------------------------------------------------
* Function: session_start
*
@@ -297,7 +289,7 @@ session_stop(struct mirror_session *session)
static struct mirror_session *
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;
#if 0 /* TODO: behaviro option */
char logpath[H5FD_MIRROR_XMIT_FILEPATH_MAX] = "";
@@ -344,7 +336,6 @@ error:
return NULL;
}
-
/* ---------------------------------------------------------------------------
* Function: _xmit_reply
*
@@ -364,17 +355,14 @@ _xmit_reply(struct mirror_session *session)
mirror_log(session->loginfo, V_ALL, "_xmit_reply()");
reply->pub.xmit_count = session->xmit_count++;
- if (H5FD_mirror_xmit_encode_reply(xmit_buf,
- (const H5FD_mirror_xmit_reply_t *)reply)
- != H5FD_MIRROR_XMIT_REPLY_SIZE)
- {
+ if (H5FD_mirror_xmit_encode_reply(xmit_buf, (const H5FD_mirror_xmit_reply_t *)reply) !=
+ H5FD_MIRROR_XMIT_REPLY_SIZE) {
mirror_log(session->loginfo, V_ERR, "can't encode reply");
return -1;
}
mirror_log(session->loginfo, V_ALL, "reply xmit data\n```");
- mirror_log_bytes(session->loginfo, V_ALL, H5FD_MIRROR_XMIT_REPLY_SIZE,
- (const unsigned char *)xmit_buf);
+ mirror_log_bytes(session->loginfo, V_ALL, H5FD_MIRROR_XMIT_REPLY_SIZE, (const unsigned char *)xmit_buf);
mirror_log(session->loginfo, V_ALL, "```");
if (HDwrite(session->sockfd, xmit_buf, H5FD_MIRROR_XMIT_REPLY_SIZE) < 0) {
@@ -385,7 +373,6 @@ _xmit_reply(struct mirror_session *session)
return 0;
} /* end _xmit_reply() */
-
/* ---------------------------------------------------------------------------
* Function: reply_ok
*
@@ -408,7 +395,6 @@ reply_ok(struct mirror_session *session)
return _xmit_reply(session);
} /* end reply_ok() */
-
/* ---------------------------------------------------------------------------
* Function: reply_error
*
@@ -420,8 +406,7 @@ reply_ok(struct mirror_session *session)
* ---------------------------------------------------------------------------
*/
static int
-reply_error(struct mirror_session *session,
- const char *msg)
+reply_error(struct mirror_session *session, const char *msg)
{
H5FD_mirror_xmit_reply_t *reply = &(session->reply);
@@ -430,11 +415,10 @@ reply_error(struct mirror_session *session,
mirror_log(session->loginfo, V_ALL, "reply_error(%s)", msg);
reply->status = H5FD_MIRROR_STATUS_ERROR;
- HDsnprintf(reply->message, H5FD_MIRROR_STATUS_MESSAGE_MAX-1, "%s", msg);
+ HDsnprintf(reply->message, H5FD_MIRROR_STATUS_MESSAGE_MAX - 1, "%s", msg);
return _xmit_reply(session);
} /* end reply_error() */
-
/* ---------------------------------------------------------------------------
* Function: do_close
*
@@ -473,7 +457,6 @@ do_close(struct mirror_session *session)
return 0;
} /* end do_close() */
-
/* ---------------------------------------------------------------------------
* Function: do_lock
*
@@ -483,8 +466,7 @@ do_close(struct mirror_session *session)
* ---------------------------------------------------------------------------
*/
static int
-do_lock(struct mirror_session *session,
- const unsigned char *xmit_buf)
+do_lock(struct mirror_session *session, const unsigned char *xmit_buf)
{
size_t decode_ret = 0;
H5FD_mirror_xmit_lock_t xmit_lock;
@@ -522,7 +504,6 @@ do_lock(struct mirror_session *session,
return 0;
} /* end do_lock() */
-
/* ---------------------------------------------------------------------------
* Function: do_open
*
@@ -532,12 +513,11 @@ do_lock(struct mirror_session *session,
* ---------------------------------------------------------------------------
*/
static int
-do_open(struct mirror_session *session,
- const H5FD_mirror_xmit_open_t *xmit_open)
+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;
+ hid_t fapl_id = H5I_INVALID_HID;
+ unsigned _flags = 0;
+ haddr_t _maxaddr = HADDR_UNDEF;
HDassert(session && (session->magic == MW_SESSION_MAGIC) && xmit_open &&
TRUE == H5FD_mirror_xmit_is_open(xmit_open));
@@ -555,11 +535,11 @@ do_open(struct mirror_session *session,
goto error;
}
- session->xmit_count = 1;
- session->token = xmit_open->pub.session_token;
+ session->xmit_count = 1;
+ session->token = xmit_open->pub.session_token;
session->reply.pub.session_token = session->token;
- _flags = (unsigned)xmit_open->flags;
+ _flags = (unsigned)xmit_open->flags;
_maxaddr = (haddr_t)xmit_open->maxaddr;
/* Check whether the native size_t on the remote machine (Driver) is larger
@@ -567,13 +547,11 @@ do_open(struct mirror_session *session,
* The blob is always an 8-byte bitfield -- check its contents.
*/
if (xmit_open->size_t_blob > (uint64_t)((size_t)(-1))) {
- mirror_log(session->loginfo, V_WARN,
- "Driver size_t is larger than our own");
+ mirror_log(session->loginfo, V_WARN, "Driver size_t is larger than our own");
}
- mirror_log(session->loginfo, V_INFO,
- "to open file %s (flags %d) (maxaddr %d)",
- xmit_open->filename, _flags, _maxaddr);
+ mirror_log(session->loginfo, V_INFO, "to open file %s (flags %d) (maxaddr %d)", xmit_open->filename,
+ _flags, _maxaddr);
/* Explicitly use Sec2 as the underlying driver for now.
*/
@@ -613,14 +591,12 @@ do_open(struct mirror_session *session,
error:
if (fapl_id > 0) {
- H5E_BEGIN_TRY {
- (void)H5Pclose(fapl_id);
- } H5E_END_TRY;
+ H5E_BEGIN_TRY { (void)H5Pclose(fapl_id); }
+ H5E_END_TRY;
}
return -1;
} /* end do_open() */
-
/* ---------------------------------------------------------------------------
* Function: do_set_eoa
*
@@ -630,8 +606,7 @@ error:
* ---------------------------------------------------------------------------
*/
static int
-do_set_eoa(struct mirror_session *session,
- const unsigned char *xmit_buf)
+do_set_eoa(struct mirror_session *session, const unsigned char *xmit_buf)
{
size_t decode_ret = 0;
H5FD_mirror_xmit_eoa_t xmit_seoa;
@@ -653,13 +628,9 @@ do_set_eoa(struct mirror_session *session,
return -1;
}
- mirror_log(session->loginfo, V_INFO, "set EOA addr %d",
- xmit_seoa.eoa_addr);
+ 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(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;
@@ -674,7 +645,6 @@ do_set_eoa(struct mirror_session *session,
return 0;
} /* end do_set_eoa() */
-
/* ---------------------------------------------------------------------------
* Function: do_truncate
*
@@ -684,7 +654,7 @@ do_set_eoa(struct mirror_session *session,
* ---------------------------------------------------------------------------
*/
static int
-do_truncate(struct mirror_session *session)
+do_truncate(struct mirror_session *session)
{
HDassert(session && (session->magic == MW_SESSION_MAGIC));
@@ -707,7 +677,6 @@ do_truncate(struct mirror_session *session)
return 0;
} /* end do_truncate() */
-
/* ---------------------------------------------------------------------------
* Function: do_unlock
*
@@ -717,7 +686,7 @@ do_truncate(struct mirror_session *session)
* ---------------------------------------------------------------------------
*/
static int
-do_unlock(struct mirror_session *session)
+do_unlock(struct mirror_session *session)
{
HDassert(session && (session->magic == MW_SESSION_MAGIC));
@@ -738,7 +707,6 @@ do_unlock(struct mirror_session *session)
return 0;
} /* end do_unlock() */
-
/* ---------------------------------------------------------------------------
* Function: do_write
*
@@ -754,15 +722,14 @@ do_unlock(struct mirror_session *session)
* ---------------------------------------------------------------------------
*/
static int
-do_write(struct mirror_session *session,
- const unsigned char *xmit_buf)
+do_write(struct mirror_session *session, const unsigned char *xmit_buf)
{
- size_t decode_ret = 0;
- haddr_t addr = 0;
- haddr_t sum_bytes_written = 0;
- H5FD_mem_t type = 0;
- char *buf = NULL;
- ssize_t nbytes_in_packet = 0;
+ size_t decode_ret = 0;
+ haddr_t addr = 0;
+ haddr_t sum_bytes_written = 0;
+ H5FD_mem_t type = 0;
+ char * buf = NULL;
+ ssize_t nbytes_in_packet = 0;
H5FD_mirror_xmit_write_t xmit_write;
HDassert(session && (session->magic == MW_SESSION_MAGIC) && xmit_buf);
@@ -807,9 +774,7 @@ do_write(struct mirror_session *session,
return -1;
}
- mirror_log(session->loginfo, V_INFO, "to write %zu bytes at %zu",
- xmit_write.size,
- addr);
+ mirror_log(session->loginfo, V_INFO, "to write %zu bytes at %zu", xmit_write.size, addr);
/* The given write may be:
* 1. larger than the allowed single buffer size
@@ -820,31 +785,25 @@ do_write(struct mirror_session *session,
*/
sum_bytes_written = 0;
do {
- nbytes_in_packet = HDread(session->sockfd, buf,
- H5FD_MIRROR_DATA_BUFFER_MAX);
+ nbytes_in_packet = HDread(session->sockfd, buf, H5FD_MIRROR_DATA_BUFFER_MAX);
if (-1 == nbytes_in_packet) {
mirror_log(session->loginfo, V_ERR, "can't read into databuffer");
reply_error(session, "can't read data buffer");
return -1;
}
- mirror_log(session->loginfo, V_INFO, "received %zd bytes",
- nbytes_in_packet);
+ mirror_log(session->loginfo, V_INFO, "received %zd bytes", nbytes_in_packet);
if (HEXDUMP_WRITEDATA) {
mirror_log(session->loginfo, V_ALL, "DATA:\n```");
- mirror_log_bytes(session->loginfo, V_ALL, nbytes_in_packet,
- (const unsigned char *)buf);
+ mirror_log_bytes(session->loginfo, V_ALL, nbytes_in_packet, (const unsigned char *)buf);
mirror_log(session->loginfo, V_ALL, "```");
}
- mirror_log(session->loginfo, V_INFO, "writing %zd bytes at %zu",
- nbytes_in_packet,
- (addr + sum_bytes_written));
+ 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, buf)
- < 0)
- {
+ if (H5FDwrite(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");
return -1;
@@ -866,7 +825,6 @@ do_write(struct mirror_session *session,
return 0;
} /* end do_write() */
-
/* ---------------------------------------------------------------------------
* Function: receive_communique
*
@@ -881,21 +839,15 @@ do_write(struct mirror_session *session,
* ---------------------------------------------------------------------------
*/
static int
-receive_communique(
- struct mirror_session *session,
- struct sock_comm *comm)
+receive_communique(struct mirror_session *session, struct sock_comm *comm)
{
- ssize_t read_ret = 0;
- size_t decode_ret;
+ ssize_t read_ret = 0;
+ size_t decode_ret;
H5FD_mirror_xmit_t *X = comm->xmit_recd;
- HDassert((session != NULL) && \
- (session->magic == MW_SESSION_MAGIC) && \
- (comm != NULL) && \
- (comm->magic == MW_SOCK_COMM_MAGIC) && \
- (comm->xmit_recd != NULL) && \
- (comm->raw != NULL) && \
- (comm->raw_size >= H5FD_MIRROR_XMIT_BUFFER_MAX) );
+ HDassert((session != NULL) && (session->magic == MW_SESSION_MAGIC) && (comm != NULL) &&
+ (comm->magic == MW_SOCK_COMM_MAGIC) && (comm->xmit_recd != NULL) && (comm->raw != NULL) &&
+ (comm->raw_size >= H5FD_MIRROR_XMIT_BUFFER_MAX));
mirror_log(session->loginfo, V_INFO, "receive_communique()");
@@ -913,8 +865,7 @@ receive_communique(
mirror_log(session->loginfo, V_INFO, "received %zd bytes", read_ret);
if (HEXDUMP_XMITS) {
mirror_log(session->loginfo, V_ALL, "```", read_ret);
- mirror_log_bytes(session->loginfo, V_ALL, (size_t)read_ret,
- (const unsigned char *)comm->raw);
+ mirror_log_bytes(session->loginfo, V_ALL, (size_t)read_ret, (const unsigned char *)comm->raw);
mirror_log(session->loginfo, V_ALL, "```");
} /* end if hexdump transmissions received */
@@ -925,12 +876,10 @@ receive_communique(
goto done;
}
- decode_ret = H5FD_mirror_xmit_decode_header(X,
- (const unsigned char *)comm->raw);
+ decode_ret = H5FD_mirror_xmit_decode_header(X, (const unsigned char *)comm->raw);
if (H5FD_MIRROR_XMIT_HEADER_SIZE != decode_ret) {
- mirror_log(session->loginfo, V_ERR,
- "header decode size mismatch: expected (%z), got (%z)",
- H5FD_MIRROR_XMIT_HEADER_SIZE, decode_ret);
+ mirror_log(session->loginfo, V_ERR, "header decode size mismatch: expected (%z), got (%z)",
+ H5FD_MIRROR_XMIT_HEADER_SIZE, decode_ret);
/* Try to tell Driver that it should stop */
reply_error(session, "xmit size mismatch");
goto error;
@@ -944,15 +893,14 @@ receive_communique(
}
if (session->xmit_count != X->xmit_count) {
- mirror_log(session->loginfo, V_ERR,
- "xmit_count mismatch exp:%d recd:%d",
- session->xmit_count, X->xmit_count);
+ mirror_log(session->loginfo, V_ERR, "xmit_count mismatch exp:%d recd:%d", session->xmit_count,
+ X->xmit_count);
/* Try to tell Driver that it should stop */
reply_error(session, "xmit_count mismatch");
goto error;
}
- if ( (session->token > 0) && (session->token != X->session_token) ) {
+ if ((session->token > 0) && (session->token != X->session_token)) {
mirror_log(session->loginfo, V_ERR, "wrong session");
/* Try to tell Driver that it should stop */
reply_error(session, "wrong session");
@@ -968,7 +916,6 @@ error:
return -1;
} /* end receive_communique() */
-
/* ---------------------------------------------------------------------------
* Function: process_instructions
*
@@ -980,19 +927,19 @@ error:
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 */
+ struct sock_comm comm;
+ char xmit_buf[H5FD_MIRROR_XMIT_BUFFER_MAX]; /* raw bytes */
+ 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()");
- comm.magic = MW_SOCK_COMM_MAGIC;
- comm.recd_die = 0; /* Flag for program to terminate */
+ 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 = xmit_buf;
+ comm.raw_size = sizeof(xmit_buf);
while (1) { /* sill-listening infinite loop */
@@ -1006,56 +953,55 @@ process_instructions(struct mirror_session *session)
goto done;
}
- switch(xmit_recd.op) {
- case H5FD_MIRROR_OP_CLOSE:
- if (do_close(session) < 0) {
- return -1;
- }
- goto done;
- case H5FD_MIRROR_OP_LOCK:
- if (do_lock(session, (const unsigned char *)xmit_buf) < 0) {
- return -1;
- }
- 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;
- case H5FD_MIRROR_OP_SET_EOA:
- if (do_set_eoa(session, (const unsigned char *)xmit_buf) < 0) {
+ switch (xmit_recd.op) {
+ case H5FD_MIRROR_OP_CLOSE:
+ if (do_close(session) < 0) {
+ return -1;
+ }
+ goto done;
+ case H5FD_MIRROR_OP_LOCK:
+ if (do_lock(session, (const unsigned char *)xmit_buf) < 0) {
+ return -1;
+ }
+ 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;
- }
- break;
- case H5FD_MIRROR_OP_TRUNCATE:
- if (do_truncate(session) < 0) {
+ case H5FD_MIRROR_OP_SET_EOA:
+ if (do_set_eoa(session, (const unsigned char *)xmit_buf) < 0) {
+ return -1;
+ }
+ break;
+ case H5FD_MIRROR_OP_TRUNCATE:
+ if (do_truncate(session) < 0) {
+ return -1;
+ }
+ break;
+ case H5FD_MIRROR_OP_UNLOCK:
+ if (do_unlock(session) < 0) {
+ return -1;
+ }
+ break;
+ case H5FD_MIRROR_OP_WRITE:
+ if (do_write(session, (const unsigned char *)xmit_buf) < 0) {
+ return -1;
+ }
+ break;
+ default:
+ mirror_log(session->loginfo, V_ERR, "unrecognized transmission");
+ reply_error(session, "unrecognized transmission");
return -1;
- }
- break;
- case H5FD_MIRROR_OP_UNLOCK:
- if (do_unlock(session) < 0) {
- return -1;
- }
- break;
- case H5FD_MIRROR_OP_WRITE:
- if (do_write(session, (const unsigned char *)xmit_buf) < 0) {
- return -1;
- }
- break;
- default:
- mirror_log(session->loginfo, V_ERR, "unrecognized transmission");
- reply_error(session, "unrecognized transmission");
- return -1;
} /* end switch (xmit_recd.op) */
} /* end while still listening */
done:
- comm.magic = 0; /* invalidate structure, on principle */
+ comm.magic = 0; /* invalidate structure, on principle */
xmit_recd.magic = 0; /* invalidate structure, on principle */
return 0;
} /* end process_instructions() */
-
/* ---------------------------------------------------------------------------
* Function: run_writer
*
@@ -1076,8 +1022,8 @@ done:
herr_t
run_writer(int socketfd, H5FD_mirror_xmit_open_t *xmit_open)
{
- struct mirror_session *session = NULL;
- int ret_value = SUCCEED;
+ struct mirror_session *session = NULL;
+ int ret_value = SUCCEED;
session = session_start(socketfd, xmit_open);
if (NULL == session) {
@@ -1086,8 +1032,7 @@ run_writer(int socketfd, H5FD_mirror_xmit_open_t *xmit_open)
}
else {
if (process_instructions(session) < 0) {
- mirror_log(session->loginfo, V_ERR,
- "problem processing instructions");
+ mirror_log(session->loginfo, V_ERR, "problem processing instructions");
ret_value = FAIL;
}
if (session_stop(session) < 0) {
@@ -1100,4 +1045,3 @@ run_writer(int socketfd, H5FD_mirror_xmit_open_t *xmit_open)
} /* end run_writer */
#endif /* H5_HAVE_MIRROR_VFD */
-