Skip to content

Commit

Permalink
Switched to a linked list for storing node names.
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Nov 16, 2011
1 parent b2c333b commit a143a03
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
all:
cc -Wall -o ib2slurm ib2slurm.c -I/usr/include/infiniband -libnetdisc
cc -Wextra -Wall -g -o ib2slurm ib2slurm.c -I/usr/include/infiniband -libnetdisc

clean:
rm -f ib2slurm core.*
65 changes: 46 additions & 19 deletions ib2slurm.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ void output_nodelist(char *tag, int type, ib2slurm_opts_t* opts, ibnd_node_t* no
ibnd_port_t* port;
int p = 0;

fprintf(stdout, " %s", tag);
ib2slurm_list_t list_head;
list_head.str = NULL;
list_head.next = NULL;

ib2slurm_list_t* list_cur = &list_head;

/*
* Lets go through all the ports on this switch to see if anything is
Expand All @@ -46,25 +50,49 @@ void output_nodelist(char *tag, int type, ib2slurm_opts_t* opts, ibnd_node_t* no
for(p = 1; p <= node->numports; p++) {
port = node->ports[p];

if(port && port->remoteport) {

/*
* Only print out the node types that match the tag printed
* before it.
*/
if(port->remoteport->node->type == type) {

/* Always attempt a node lookup, since slurm requires it. */
if(opts->lookup_flag || type == IB_NODE_CA) {
char* remoteswitch = node_name(port->remoteport->node, opts);
fprintf(stdout, "%s,", remoteswitch);
free(remoteswitch);
} else {
fprintf(stdout, "%" PRIx64 ", ", port->remoteport->guid);
}
/*
* Only print out the node types that match the tag printed
* before it.
*/
if(port && port->remoteport && port->remoteport->node->type == type) {

/* Always attempt a node lookup, since slurm requires it. */
if(opts->lookup_flag || type == IB_NODE_CA) {
char* remote = node_name(port->remoteport->node, opts);

list_cur->str = remote;
list_cur->next = (ib2slurm_list_t*)malloc(sizeof(ib2slurm_list_t));

list_cur = list_cur->next;
list_cur->str = NULL;
list_cur->next = NULL;
} else {
char* buf = (char*)malloc(sizeof(char) * 512);
sprintf(buf, "%" PRIx64, port->remoteport->guid);

list_cur->str = buf;
list_cur->next = (ib2slurm_list_t*)malloc(sizeof(ib2slurm_list_t));

list_cur = list_cur->next;
list_cur->str = NULL;
list_cur->next = NULL;
}
}
}

if(list_head.str != NULL) {
fprintf(stdout, " %s", tag);

for(list_cur = &list_head; list_cur->next != NULL; list_cur = list_cur->next) {
fprintf(stdout, "%s", list_cur->str);

if(list_cur->next->str != NULL) {
fprintf(stdout, ", ");
}
}
}

/* TODO: free the list elements. */
}

/*
Expand Down Expand Up @@ -105,7 +133,6 @@ void output_header()
int main(int argc, char** argv)
{
ibnd_fabric_t* fabric = NULL;
struct ibnd_config config = {0};
char* ibd_ca = NULL;
int ibd_ca_port = 0;

Expand All @@ -132,7 +159,7 @@ int main(int argc, char** argv)

opts.node_name_map = open_node_name_map(node_name_map_file);

if((fabric = ibnd_discover_fabric(ibd_ca, ibd_ca_port, NULL, &config)) == NULL) {
if((fabric = ibnd_discover_fabric(ibd_ca, ibd_ca_port, NULL, 0)) == NULL) {
fprintf(stderr, "IB discover failed.\n");
exit(EXIT_FAILURE);
}
Expand Down
5 changes: 5 additions & 0 deletions ib2slurm.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ typedef struct ib2slurm_opts_t {
int compress_flag;
} ib2slurm_opts_t;

typedef struct ib2slurm_list_t {
char* str;
struct ib2slurm_list_t* next;
} ib2slurm_list_t;

void switch_iter_func(ibnd_node_t* node, void* user_data);
void output_nodelist(char *tag, int type, ib2slurm_opts_t* opts, ibnd_node_t* node);
char* node_name(ibnd_node_t* node, ib2slurm_opts_t* opts);
Expand Down

0 comments on commit a143a03

Please sign in to comment.