cluster - Add 'circ <msgid>' command to cluster debug shell
authorMatthew Dillon <dillon@apollo.backplane.com>
Tue, 4 Dec 2012 06:00:37 +0000 (22:00 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Tue, 4 Dec 2012 06:00:37 +0000 (22:00 -0800)
* Add a debug shell command to help test virtual circuits.

sbin/hammer2/cmd_debug.c

index 6e68b0d..f7e3ecc 100644 (file)
@@ -169,6 +169,7 @@ shell_ttymsg(dmsg_iocom_t *iocom)
 }
 
 static void shell_span(dmsg_circuit_t *circuit, char *cmdbuf);
+static void shell_circ(dmsg_circuit_t *circuit, char *cmdbuf);
 
 void
 hammer2_shell_parse(dmsg_msg_t *msg)
@@ -188,6 +189,7 @@ hammer2_shell_parse(dmsg_msg_t *msg)
        } else if (strcmp(cmd, "help") == 0 || strcmp(cmd, "?") == 0) {
                dmsg_circuit_printf(circuit, "help            Command help\n");
                dmsg_circuit_printf(circuit, "span <host>     Span to target host\n");
+               dmsg_circuit_printf(circuit, "circ <msgid>    Create VC to msgid of rx SPAN\n");
                dmsg_circuit_printf(circuit, "tree            Dump spanning tree\n");
        } else {
                dmsg_circuit_printf(circuit, "Unrecognized command: %s\n", cmd);
@@ -215,7 +217,9 @@ shell_span(dmsg_circuit_t *circuit, char *cmdbuf)
         * Start master service
         */
        if (fd < 0) {
-               dmsg_circuit_printf(circuit, "Connection to %s failed\n", hostname);
+               dmsg_circuit_printf(circuit,
+                                   "Connection to %s failed\n",
+                                   hostname);
        } else {
                dmsg_circuit_printf(circuit, "Connected to %s\n", hostname);
 
@@ -224,12 +228,53 @@ shell_span(dmsg_circuit_t *circuit, char *cmdbuf)
                info->fd = fd;
                info->detachme = 1;
                info->dbgmsg_callback = hammer2_shell_parse;
+               info->label = strdup("client");
 
                pthread_create(&thread, NULL, dmsg_master_service, info);
                /*pthread_join(thread, &res);*/
        }
 }
 
+static void shell_circ_reply(dmsg_msg_t *msg);
+
+static void
+shell_circ(dmsg_circuit_t *circuit, char *cmdbuf)
+{
+       uint64_t msgid = strtoull(cmdbuf, NULL, 16);
+       dmsg_state_t *state;
+       dmsg_msg_t *msg;
+
+       if (dmsg_debug_findspan(msgid, &state) == 0) {
+               dmsg_circuit_printf(circuit, "Found state %p\n", state);
+
+               dmsg_circuit_printf(circuit, "Establishing CIRC\n");
+               msg = dmsg_msg_alloc(&state->iocom->circuit0, 0,
+                                    DMSG_LNK_CIRC | DMSGF_CREATE,
+                                    shell_circ_reply, circuit);
+               msg->any.lnk_circ.target = state->msgid;
+               dmsg_msg_write(msg);
+       } else {
+               dmsg_circuit_printf(circuit,
+                                   "Unable to locate %016jx\n",
+                                   (intmax_t)msgid);
+       }
+}
+
+static void
+shell_circ_reply(dmsg_msg_t *msg)
+{
+       dmsg_circuit_t *circ = msg->state->any.circ;
+
+       if (msg->any.head.cmd & DMSGF_DELETE) {
+               dmsg_circuit_printf(circ, "rxmsg DELETE error %d\n",
+                                   msg->any.head.error);
+               msg->state->any.circ = NULL;
+       } else {
+               dmsg_circuit_printf(circ, "rxmsg result error %d\n",
+                                   msg->any.head.error);
+       }
+}
+
 /************************************************************************
  *                             DEBUGSPAN                               *
  ************************************************************************