1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
32 * Copyright (c) 2003 Los Alamos National Laboratory (LANL)
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
40 #include <sys/types.h>
41 #include <sys/socket.h>
42 #include <netinet/tcp.h>
47 #include <sys/ioctl.h>
52 #include <lnet/api-support.h>
53 #include <lnet/lib-types.h>
58 * portals always uses unit 0
59 * Can this be configurable?
64 usage(char *prg, int h)
68 " %s [-l] [-n hostname] [-L] [hostnames]\n", prg);
71 printf("Print Myrinet Global network ids for specified hosts\n"
72 "-l print local host's ID\n"
73 "-n hostname print given host's ID\n"
74 "-L print Myringet local net ID too\n"
75 "[hostnames] print ids of given hosts (local if none)\n");
79 print_gmid(char *name, int name_fieldlen, int show_local_id)
81 struct gm_port *gm_port;
83 gm_status_t gm_status;
84 unsigned int local_id;
85 unsigned int global_id;
87 gm_status = gm_init();
88 if (gm_status != GM_SUCCESS) {
89 fprintf(stderr, "gm_init: %s\n", gm_strerror(gm_status));
94 gm_status = gm_open(&gm_port, GM_UNIT, gm_port_id, "gmnalnid",
96 if (gm_status != GM_SUCCESS) {
97 int num_ports = gm_num_ports(gm_port);
99 /* Couldn't open port 2, try 4 ... num_ports */
100 for (gm_port_id = 4; gm_port_id < num_ports; gm_port_id++) {
101 gm_status = gm_open(&gm_port, GM_UNIT, gm_port_id,
102 "gmnalnid", GM_API_VERSION);
103 if (gm_status == GM_SUCCESS)
107 if (gm_status != GM_SUCCESS) {
108 fprintf(stderr, "gm_open: %s\n",gm_strerror(gm_status));
117 gm_status = gm_host_name_to_node_id_ex(gm_port, 1000000, name,
119 if (gm_status != GM_SUCCESS) {
120 fprintf(stderr, "gm_host_name_to_node_id_ex(%s): %s\n",
121 name, gm_strerror(gm_status));
126 gm_status = gm_node_id_to_global_id(gm_port, local_id, &global_id) ;
127 if (gm_status != GM_SUCCESS) {
128 fprintf(stderr, "gm_node_id_to_global_id(%s:%d): %s\n",
129 name, local_id, gm_strerror(gm_status));
133 if (name_fieldlen > 0)
134 printf ("%*s ", name_fieldlen, name);
137 printf("0x%x\n", global_id);
139 printf("local 0x%x global 0x%x\n", local_id, global_id);
150 main (int argc, char **argv)
156 int show_local_id = 0;
158 while ((c = getopt(argc, argv, "n:lLh")) != -1)
169 gmrc = print_gmid(optarg, 0, show_local_id);
170 return (gmrc == GM_SUCCESS) ? 0 : 1;
173 gmrc = print_gmid(NULL, 0, show_local_id);
174 return (gmrc == GM_SUCCESS) ? 0 : 1;
181 if (optind == argc) {
182 gmrc = print_gmid(NULL, 0, show_local_id);
183 return (gmrc == GM_SUCCESS) ? 0 : 1;
186 if (optind != argc - 1)
187 for (c = optind; c < argc; c++)
188 if (strlen(argv[c]) > max_namelen)
189 max_namelen = strlen(argv[c]);
193 for (c = optind; c < argc; c++) {
194 gmrc = print_gmid(argv[c], max_namelen, show_local_id);
196 if (gmrc != GM_SUCCESS)