From 7dc0f844a404685d76d02c79c241ad11234db455 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 7 Aug 2012 12:40:24 -0700 Subject: [PATCH] hammer2 - spanning tree and messaging work * Fix numerous bugs and cleanup the messaging infrastructure further. Fix issues with state tracking and incorrect message flags, assert that flags are correct. * Fix issues with connection termination. All active transactions must be completely closed from both ends before the iocom can be destroyed. Fix bugs in the MSGF_DELETE message simulator when a socket error occurs (simulating the other end closing any active transactions going over the iocom). * Implement the spanning tree relay code. The relay code is even relatively optimal though ultimately we need to add additional filters to make client<->service rendezvous's less cpu intensive. --- sbin/hammer2/cmd_debug.c | 10 +- sbin/hammer2/cmd_service.c | 2 +- sbin/hammer2/hammer2.h | 6 +- sbin/hammer2/main.c | 21 ++ sbin/hammer2/msg.c | 620 ++++++++++++++++++++++--------------- sbin/hammer2/msg_lnk.c | 300 +++++++++++++++--- sbin/hammer2/network.h | 12 +- 7 files changed, 670 insertions(+), 301 deletions(-) diff --git a/sbin/hammer2/cmd_debug.c b/sbin/hammer2/cmd_debug.c index e2169e3138..6dda52b7e9 100644 --- a/sbin/hammer2/cmd_debug.c +++ b/sbin/hammer2/cmd_debug.c @@ -98,7 +98,7 @@ cmd_shell(const char *hostname) printf("debug: connected\n"); msg = hammer2_msg_alloc(&iocom, 0, HAMMER2_DBG_SHELL); - hammer2_msg_write(&iocom, msg, NULL, NULL); + hammer2_msg_write(&iocom, msg, NULL, NULL, NULL); hammer2_iocom_core(&iocom, shell_recv, shell_send, shell_tty); fprintf(stderr, "debug: disconnected\n"); @@ -168,7 +168,7 @@ static void shell_send(hammer2_iocom_t *iocom) { - hammer2_iocom_flush(iocom); + hammer2_iocom_flush1(iocom); } static @@ -186,7 +186,7 @@ shell_tty(hammer2_iocom_t *iocom) ++len; msg = hammer2_msg_alloc(iocom, len, HAMMER2_DBG_SHELL); bcopy(buf, msg->aux_data, len); - hammer2_msg_write(iocom, msg, NULL, NULL); + hammer2_msg_write(iocom, msg, NULL, NULL, NULL); } else { /* * Set EOF flag without setting any error code for normal @@ -274,7 +274,7 @@ iocom_printf(hammer2_iocom_t *iocom, uint32_t cmd, const char *ctl, ...) HAMMER2_MSGF_REPLY); bcopy(buf, rmsg->aux_data, len); - hammer2_msg_write(iocom, rmsg, NULL, NULL); + hammer2_msg_write(iocom, rmsg, NULL, NULL, NULL); } /************************************************************************ @@ -349,14 +349,12 @@ show_bref(int fd, int tab, int bi, hammer2_blockref_t *bref) bytes = (size_t)1 << (bref->data_off & HAMMER2_OFF_MASK_RADIX); if (bytes < HAMMER2_MINIOSIZE || bytes > sizeof(media)) { printf("(bad block size %zd)\n", bytes); - sleep(1); return; } if (bref->type != HAMMER2_BREF_TYPE_DATA || VerboseOpt >= 1) { lseek(fd, bref->data_off & ~HAMMER2_OFF_MASK_RADIX, 0); if (read(fd, &media, bytes) != (ssize_t)bytes) { printf("(media read failed)\n"); - sleep(1); return; } } diff --git a/sbin/hammer2/cmd_service.c b/sbin/hammer2/cmd_service.c index 9e708a7a9a..848a1e6d27 100644 --- a/sbin/hammer2/cmd_service.c +++ b/sbin/hammer2/cmd_service.c @@ -272,5 +272,5 @@ static void master_link_tx(hammer2_iocom_t *iocom) { - hammer2_iocom_flush(iocom); + hammer2_iocom_flush1(iocom); } diff --git a/sbin/hammer2/hammer2.h b/sbin/hammer2/hammer2.h index 3e215887c1..62a8833e39 100644 --- a/sbin/hammer2/hammer2.h +++ b/sbin/hammer2/hammer2.h @@ -102,6 +102,7 @@ int cmd_remote_connect(const char *sel_path, const char *url); int cmd_remote_disconnect(const char *sel_path, const char *url); int cmd_remote_status(const char *sel_path, int all_opt); +int cmd_pfs_getid(const char *sel_path, const char *name, int privateid); int cmd_pfs_list(const char *sel_path); int cmd_pfs_create(const char *sel_path, const char *name, uint8_t pfs_type, const char *uuid_str); @@ -141,10 +142,11 @@ void hammer2_iocom_core(hammer2_iocom_t *iocom, hammer2_msg_t *hammer2_ioq_read(hammer2_iocom_t *iocom); void hammer2_msg_write(hammer2_iocom_t *iocom, hammer2_msg_t *msg, void (*func)(hammer2_state_t *, hammer2_msg_t *), - void *data); + void *data, hammer2_state_t **statep); void hammer2_iocom_drain(hammer2_iocom_t *iocom); -void hammer2_iocom_flush(hammer2_iocom_t *iocom); +void hammer2_iocom_flush1(hammer2_iocom_t *iocom); +void hammer2_iocom_flush2(hammer2_iocom_t *iocom); void hammer2_state_cleanuprx(hammer2_iocom_t *iocom, hammer2_msg_t *msg); void hammer2_state_free(hammer2_state_t *state); diff --git a/sbin/hammer2/main.c b/sbin/hammer2/main.c index 75caad5a64..b0dd2fb873 100644 --- a/sbin/hammer2/main.c +++ b/sbin/hammer2/main.c @@ -54,6 +54,7 @@ main(int ac, char **av) int ch; srandomdev(); + signal(SIGPIPE, SIG_IGN); /* * Core options @@ -153,6 +154,24 @@ main(int ac, char **av) * Get status of PFS and its connections (-a for all PFSs) */ ecode = cmd_remote_status(sel_path, all_opt); + } else if (strcmp(av[0], "pfs-clid") == 0) { + /* + * Print cluster id (uuid) for specific PFS + */ + if (ac < 2) { + fprintf(stderr, "pfs-clid: requires name\n"); + usage(1); + } + ecode = cmd_pfs_getid(sel_path, av[1], 0); + } else if (strcmp(av[0], "pfs-fsid") == 0) { + /* + * Print private id (uuid) for specific PFS + */ + if (ac < 2) { + fprintf(stderr, "pfs-fsid: requires name\n"); + usage(1); + } + ecode = cmd_pfs_getid(sel_path, av[1], 1); } else if (strcmp(av[0], "pfs-list") == 0) { /* * List all PFSs @@ -309,6 +328,8 @@ usage(int code) " disconnect Del cluster link\n" " status Report cluster status\n" " pfs-list List PFSs\n" + " pfs-clid