[ofa-general] Re: [IBSIM] add ReLink command
Sasha Khapyorsky
sashak at voltaire.com
Sun Aug 31 06:45:03 PDT 2008
Hi Al,
On 16:01 Thu 28 Aug , Al Chu wrote:
> Hey Sasha,
>
> This adds a "ReLink" command to ibsim. If a link was previously
> unlinked, you can run "ReLink" to reconnect it to whatever it was
> connected to before. It's easier than having to figure out what it was
> connected to previously and input both the local and remote ends under
> the "Link" command.
>
> The idea for this option came up when I was trying to simulate an entire
> cluster going down then going back up. Scripting the cluster to go down
> was easy ("Unlink" all CAs), but scripting it to come back up was a
> little harder since I had to figure out all the other end ports to input
> into "Link".
>
> Al
>
> --
> Albert Chu
> chu11 at llnl.gov
> 925-422-5311
> Computer Scientist
> High Performance Systems Division
> Lawrence Livermore National Laboratory
> From ec9cf72ac3dc5950337aa577f49ada6b8887d579 Mon Sep 17 00:00:00 2001
> From: Albert Chu <chu11 at llnl.gov>
> Date: Thu, 28 Aug 2008 15:25:14 -0700
> Subject: [PATCH] add relink command
>
>
> Signed-off-by: Albert Chu <chu11 at llnl.gov>
> ---
> ibsim/sim.h | 2 +
> ibsim/sim_cmd.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 70 insertions(+), 0 deletions(-)
>
> diff --git a/ibsim/sim.h b/ibsim/sim.h
> index f989252..32a4e20 100644
> --- a/ibsim/sim.h
> +++ b/ibsim/sim.h
> @@ -206,6 +206,8 @@ struct Port {
> char alias[ALIASLEN + 1];
> Node *remotenode;
> int remoteport;
> + Node *previous_remotenode;
> + int previous_remoteport;
> int errrate;
> uint16_t errattr;
> Node *node;
> diff --git a/ibsim/sim_cmd.c b/ibsim/sim_cmd.c
> index d55fb4c..39eb316 100644
> --- a/ibsim/sim_cmd.c
> +++ b/ibsim/sim_cmd.c
> @@ -149,14 +149,79 @@ static int do_link(FILE * f, char *line)
> if (link_ports(lport, rport) < 0)
> return -fprintf(f,
> "# can't link: local/remote port are already connected\n");
> +
> + lport->previous_remotenode = NULL;
> + rport->previous_remotenode = NULL;
> +
> + return 0;
> +}
> +
> +static int do_relink(FILE * f, char *line)
> +{
> + Port *lport, *rport;
> + Node *lnode;
> + char *orig = 0;
> + char *lnodeid = 0;
> + char *s = line, name[NAMELEN], *sp;
> + int lportnum = -1;
> +
> + // parse local
> + if (strsep(&s, "\""))
> + orig = strsep(&s, "\"");
> +
> + lnodeid = expand_name(orig, name, &sp);
> + if (!sp && s && *s == '[')
> + sp = s + 1;
> +
> + DEBUG("lnodeid %s port [%s", lnodeid, sp);
> + if (!(lnode = find_node(lnodeid))) {
> + fprintf(f, "# nodeid \"%s\" (%s) not found\n", orig, lnodeid);
> + return -1;
> + }
> +
> + if (sp) {
> + lportnum = strtoul(sp, &sp, 0);
> + if (lportnum < 1 || lportnum > lnode->numports) {
> + fprintf(f, "# nodeid \"%s\": bad port %d\n",
> + lnodeid, lportnum);
> + return -1;
> + }
> + } else {
> + fprintf(f, "# no local port\n");
> + return -1;
So if one asked for ReLinking whole node? I think it should be
straightforward - restore links for all ports where previous_remote*
exists. What do you think?
> + }
> +
> + lport = node_get_port(lnode, lportnum);
> +
> + if (!lport->previous_remotenode) {
> + fprintf(f, "# no previous link stored\n");
> + return -1;
> + }
> +
> + rport = node_get_port(lport->previous_remotenode, lport->previous_remoteport);
> +
> + if (link_ports(lport, rport) < 0)
> + return -fprintf(f,
> + "# can't link: local/remote port are already connected\n");
> +
> + lport->previous_remotenode = NULL;
> + rport->previous_remotenode = NULL;
> +
> return 0;
> }
>
> +
No need extra lines between functions.
> static void unlink_port(Node * lnode, Port * lport, Node * rnode, int rportnum)
> {
> Port *rport = node_get_port(rnode, rportnum);
> Port *endport;
>
> + /* save current connection for potential relink later */
> + lport->previous_remotenode = lport->remotenode;
> + lport->previous_remoteport = lport->remoteport;
> + rport->previous_remotenode = rport->remotenode;
> + rport->previous_remoteport = rport->remoteport;
> +
> lport->remotenode = rport->remotenode = 0;
> lport->remoteport = rport->remoteport = 0;
> lport->remotenodeid[0] = rport->remotenodeid[0] = 0;
> @@ -713,6 +778,7 @@ static int dump_help(FILE * f)
> fprintf(f, "\tDump [nodeid] (def all network)\n");
> fprintf(f, "\tRoute <from-lid> <to-lid>\n");
> fprintf(f, "\tLink \"nodeid\"[port] \"remoteid\"[port]\n");
> + fprintf(f, "\tReLink \"nodeid\"[port] : reconnect previously unconnected link\n");
Maybe "restore previously disconnected link(s)" help message? Actually it
is almost same :)
Sasha
> fprintf(f, "\tUnlink \"nodeid\" : remove all links of the node\n");
> fprintf(f, "\tUnlink \"nodeid\"[port]\n");
> fprintf(f,
> @@ -814,6 +880,8 @@ int do_cmd(char *buf, FILE *f)
> *
> * please specify new command support below this comment.
> */
> + else if (!strncasecmp(line, "ReLink", cmd_len))
> + r = do_relink(f, line);
> else if (*line != '\n' && *line != '\0')
> fprintf(f, "command \'%s\' unknown - skipped\n", line);
>
> --
> 1.5.4.5
>
More information about the general
mailing list