From 11f7caf4b1b8fda611182fcc6564e065330b4e14 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Thu, 25 Oct 2012 11:31:27 -0700 Subject: [PATCH] hammer2 - Messaging layer separation work part 5 * Fix debug shell callback issue --- lib/libdmsg/dmsg.h | 24 +++++++++++++----------- lib/libdmsg/msg.c | 2 ++ lib/libdmsg/service.c | 1 + sbin/hammer2/cmd_debug.c | 10 ++++++---- sbin/hammer2/cmd_service.c | 2 ++ sbin/hammer2/hammer2.h | 2 ++ 6 files changed, 26 insertions(+), 15 deletions(-) diff --git a/lib/libdmsg/dmsg.h b/lib/libdmsg/dmsg.h index c7be4f0be8..ade8ed448c 100644 --- a/lib/libdmsg/dmsg.h +++ b/lib/libdmsg/dmsg.h @@ -110,16 +110,6 @@ typedef struct dmsg_handshake dmsg_handshake_t; #define DMSG_CRYPTO_ALGO DMSG_CRYPTO_ALGO_GCM_IDX -/* - * master service thread info - */ -struct dmsg_master_service_info { - int fd; - int detachme; -}; - -typedef struct dmsg_master_service_info dmsg_master_service_info_t; - /*************************************************************************** * LOW LEVEL MESSAGING * *************************************************************************** @@ -312,7 +302,6 @@ typedef struct dmsg_iocom dmsg_iocom_t; /* * Crypto algorithm table and related typedefs. */ - typedef int (*algo_init_fn)(dmsg_ioq_t *, char *, int, char *, int, int); typedef int (*algo_enc_fn)(dmsg_ioq_t *, char *, char *, int, int *); typedef int (*algo_dec_fn)(dmsg_ioq_t *, char *, char *, int, int *); @@ -326,6 +315,18 @@ struct crypto_algo { algo_dec_fn dec_chunk; }; +/* + * Master service thread info + */ +struct dmsg_master_service_info { + int fd; + int detachme; + void (*dbgmsg_callback)(dmsg_msg_t *msg); +}; + +typedef struct dmsg_master_service_info dmsg_master_service_info_t; + + /* * icrc */ @@ -355,6 +356,7 @@ void dmsg_ioq_done(dmsg_iocom_t *iocom, dmsg_ioq_t *ioq); void dmsg_iocom_init(dmsg_iocom_t *iocom, int sock_fd, int alt_fd, void (*state_func)(dmsg_router_t *), void (*rcvmsg_func)(dmsg_msg_t *), + void (*dbgmsg_func)(dmsg_msg_t *), void (*altmsg_func)(dmsg_iocom_t *)); void dmsg_router_restate(dmsg_router_t *router, void (*state_func)(dmsg_router_t *), diff --git a/lib/libdmsg/msg.c b/lib/libdmsg/msg.c index 60e9089842..8cd50e6032 100644 --- a/lib/libdmsg/msg.c +++ b/lib/libdmsg/msg.c @@ -128,6 +128,7 @@ void dmsg_iocom_init(dmsg_iocom_t *iocom, int sock_fd, int alt_fd, void (*signal_func)(dmsg_router_t *), void (*rcvmsg_func)(dmsg_msg_t *), + void (*dbgmsg_func)(dmsg_msg_t *), void (*altmsg_func)(dmsg_iocom_t *)) { struct stat st; @@ -138,6 +139,7 @@ dmsg_iocom_init(dmsg_iocom_t *iocom, int sock_fd, int alt_fd, iocom->router->signal_callback = signal_func; iocom->router->rcvmsg_callback = rcvmsg_func; iocom->router->altmsg_callback = altmsg_func; + iocom->router->dbgmsg_callback = dbgmsg_func; /* we do not call dmsg_router_connect() for iocom routers */ pthread_mutex_init(&iocom->mtx, NULL); diff --git a/lib/libdmsg/service.c b/lib/libdmsg/service.c index 95b34a08ee..58509bd60c 100644 --- a/lib/libdmsg/service.c +++ b/lib/libdmsg/service.c @@ -57,6 +57,7 @@ dmsg_master_service(void *data) dmsg_iocom_init(&iocom, info->fd, -1, master_auth_signal, master_auth_rxmsg, + info->dbgmsg_callback, NULL); dmsg_iocom_core(&iocom); diff --git a/sbin/hammer2/cmd_debug.c b/sbin/hammer2/cmd_debug.c index 51f9555a22..aa9262746a 100644 --- a/sbin/hammer2/cmd_debug.c +++ b/sbin/hammer2/cmd_debug.c @@ -39,7 +39,6 @@ static void shell_rcvmsg(dmsg_msg_t *msg); static void shell_ttymsg(dmsg_iocom_t *iocom); -static void hammer2_shell_parse(dmsg_msg_t *msg); /************************************************************************ * SHELL * @@ -62,8 +61,11 @@ cmd_shell(const char *hostname) /* * Run the session. The remote end transmits our prompt. */ - dmsg_iocom_init(&iocom, fd, 0, NULL, shell_rcvmsg, shell_ttymsg); - iocom.router->dbgmsg_callback = hammer2_shell_parse; + dmsg_iocom_init(&iocom, fd, 0, + NULL, + shell_rcvmsg, + hammer2_shell_parse, + shell_ttymsg); fcntl(0, F_SETFL, O_NONBLOCK); printf("debug: connected\n"); @@ -168,7 +170,7 @@ shell_ttymsg(dmsg_iocom_t *iocom) static void shell_span(dmsg_router_t *router, char *cmdbuf); -static void +void hammer2_shell_parse(dmsg_msg_t *msg) { dmsg_router_t *router = msg->router; diff --git a/sbin/hammer2/cmd_service.c b/sbin/hammer2/cmd_service.c index 10b8223103..5ee6406df1 100644 --- a/sbin/hammer2/cmd_service.c +++ b/sbin/hammer2/cmd_service.c @@ -169,6 +169,7 @@ service_thread(void *data) bzero(info, sizeof(*info)); info->fd = fd; info->detachme = 1; + info->dbgmsg_callback = hammer2_shell_parse; pthread_create(&thread, NULL, dmsg_master_service, info); } return (NULL); @@ -289,5 +290,6 @@ master_reconnect(const char *mntpt) bzero(info, sizeof(*info)); info->fd = pipefds[1]; info->detachme = 1; + info->dbgmsg_callback = hammer2_shell_parse; pthread_create(&thread, NULL, dmsg_master_service, info); } diff --git a/sbin/hammer2/hammer2.h b/sbin/hammer2/hammer2.h index 543abc6523..95d473e34f 100644 --- a/sbin/hammer2/hammer2.h +++ b/sbin/hammer2/hammer2.h @@ -132,3 +132,5 @@ const char *sizetostr(hammer2_off_t size); uint32_t hammer2_icrc32(const void *buf, size_t size); uint32_t hammer2_icrc32c(const void *buf, size_t size, uint32_t crc); + +void hammer2_shell_parse(dmsg_msg_t *msg); -- 2.41.0