hammer2 - Messaging layer separation work part 5
authorMatthew Dillon <dillon@apollo.backplane.com>
Thu, 25 Oct 2012 18:31:27 +0000 (11:31 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Thu, 25 Oct 2012 18:31:27 +0000 (11:31 -0700)
* Fix debug shell callback issue

lib/libdmsg/dmsg.h
lib/libdmsg/msg.c
lib/libdmsg/service.c
sbin/hammer2/cmd_debug.c
sbin/hammer2/cmd_service.c
sbin/hammer2/hammer2.h

index c7be4f0..ade8ed4 100644 (file)
@@ -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 *),
index 60e9089..8cd50e6 100644 (file)
@@ -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);
index 95b34a0..58509bd 100644 (file)
@@ -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);
 
index 51f9555..aa92627 100644 (file)
@@ -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;
index 10b8223..5ee6406 100644 (file)
@@ -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);
 }
index 543abc6..95d473e 100644 (file)
@@ -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);