2 * -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
3 * vim:expandtab:shiftwidth=8:tabstop=8:
7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 only,
11 * as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License version 2 for more details (a copy is included
17 * in the LICENSE file that accompanied this code).
19 * You should have received a copy of the GNU General Public License
20 * version 2 along with this program; If not, see [sun.com URL with a
23 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
24 * CA 95054 USA or visit www.sun.com if you need additional information or
30 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
31 * Use is subject to license terms.
33 * Copyright (c) 2003 Los Alamos National Laboratory (LANL)
36 * This file is part of Lustre, http://www.lustre.org/
37 * Lustre is a trademark of Sun Microsystems, Inc.
41 #include <sys/types.h>
42 #include <sys/socket.h>
43 #include <netinet/tcp.h>
48 #include <sys/ioctl.h>
53 #include <lnet/api-support.h>
54 #include <lnet/lib-types.h>
59 * portals always uses unit 0
60 * Can this be configurable?
65 usage(char *prg, int h)
69 " %s [-l] [-n hostname] [-L] [hostnames]\n", prg);
72 printf("Print Myrinet Global network ids for specified hosts\n"
73 "-l print local host's ID\n"
74 "-n hostname print given host's ID\n"
75 "-L print Myringet local net ID too\n"
76 "[hostnames] print ids of given hosts (local if none)\n");
80 print_gmid(char *name, int name_fieldlen, int show_local_id)
82 struct gm_port *gm_port;
84 gm_status_t gm_status;
85 unsigned int local_id;
86 unsigned int global_id;
88 gm_status = gm_init();
89 if (gm_status != GM_SUCCESS) {
90 fprintf(stderr, "gm_init: %s\n", gm_strerror(gm_status));
95 gm_status = gm_open(&gm_port, GM_UNIT, gm_port_id, "gmnalnid",
97 if (gm_status != GM_SUCCESS) {
98 int num_ports = gm_num_ports(gm_port);
100 /* Couldn't open port 2, try 4 ... num_ports */
101 for (gm_port_id = 4; gm_port_id < num_ports; gm_port_id++) {
102 gm_status = gm_open(&gm_port, GM_UNIT, gm_port_id,
103 "gmnalnid", GM_API_VERSION);
104 if (gm_status == GM_SUCCESS)
108 if (gm_status != GM_SUCCESS) {
109 fprintf(stderr, "gm_open: %s\n",gm_strerror(gm_status));
118 gm_status = gm_host_name_to_node_id_ex(gm_port, 1000000, name,
120 if (gm_status != GM_SUCCESS) {
121 fprintf(stderr, "gm_host_name_to_node_id_ex(%s): %s\n",
122 name, gm_strerror(gm_status));
127 gm_status = gm_node_id_to_global_id(gm_port, local_id, &global_id) ;
128 if (gm_status != GM_SUCCESS) {
129 fprintf(stderr, "gm_node_id_to_global_id(%s:%d): %s\n",
130 name, local_id, gm_strerror(gm_status));
134 if (name_fieldlen > 0)
135 printf ("%*s ", name_fieldlen, name);
138 printf("0x%x\n", global_id);
140 printf("local 0x%x global 0x%x\n", local_id, global_id);
151 main (int argc, char **argv)
157 int show_local_id = 0;
159 while ((c = getopt(argc, argv, "n:lLh")) != -1)
170 gmrc = print_gmid(optarg, 0, show_local_id);
171 return (gmrc == GM_SUCCESS) ? 0 : 1;
174 gmrc = print_gmid(NULL, 0, show_local_id);
175 return (gmrc == GM_SUCCESS) ? 0 : 1;
182 if (optind == argc) {
183 gmrc = print_gmid(NULL, 0, show_local_id);
184 return (gmrc == GM_SUCCESS) ? 0 : 1;
187 if (optind != argc - 1)
188 for (c = optind; c < argc; c++)
189 if (strlen(argv[c]) > max_namelen)
190 max_namelen = strlen(argv[c]);
194 for (c = optind; c < argc; c++) {
195 gmrc = print_gmid(argv[c], max_namelen, show_local_id);
197 if (gmrc != GM_SUCCESS)