1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2003 Los Alamos National Laboratory (LANL)
6 * This file is part of Lustre, http://www.lustre.org/
8 * This file is free software; you can redistribute it and/or
9 * modify it under the terms of version 2.1 of the GNU Lesser General
10 * Public License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with Portals; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <sys/types.h>
24 #include <sys/socket.h>
25 #include <netinet/tcp.h>
30 #include <sys/ioctl.h>
35 #include <lnet/api-support.h>
36 #include <lnet/lib-types.h>
41 * portals always uses unit 0
42 * Can this be configurable?
47 usage(char *prg, int h)
51 " %s [-l] [-n hostname] [-L] [hostnames]\n", prg);
54 printf("Print Myrinet Global network ids for specified hosts\n"
55 "-l print local host's ID\n"
56 "-n hostname print given host's ID\n"
57 "-L print Myringet local net ID too\n"
58 "[hostnames] print ids of given hosts (local if none)\n");
62 print_gmid(char *name, int name_fieldlen, int show_local_id)
64 struct gm_port *gm_port;
66 gm_status_t gm_status;
67 unsigned int local_id;
68 unsigned int global_id;
70 gm_status = gm_init();
71 if (gm_status != GM_SUCCESS) {
72 fprintf(stderr, "gm_init: %s\n", gm_strerror(gm_status));
77 gm_status = gm_open(&gm_port, GM_UNIT, gm_port_id, "gmnalnid",
79 if (gm_status != GM_SUCCESS) {
80 int num_ports = gm_num_ports(gm_port);
82 /* Couldn't open port 2, try 4 ... num_ports */
83 for (gm_port_id = 4; gm_port_id < num_ports; gm_port_id++) {
84 gm_status = gm_open(&gm_port, GM_UNIT, gm_port_id,
85 "gmnalnid", GM_API_VERSION);
86 if (gm_status == GM_SUCCESS)
90 if (gm_status != GM_SUCCESS) {
91 fprintf(stderr, "gm_open: %s\n",gm_strerror(gm_status));
100 gm_status = gm_host_name_to_node_id_ex(gm_port, 1000000, name,
102 if (gm_status != GM_SUCCESS) {
103 fprintf(stderr, "gm_host_name_to_node_id_ex(%s): %s\n",
104 name, gm_strerror(gm_status));
109 gm_status = gm_node_id_to_global_id(gm_port, local_id, &global_id) ;
110 if (gm_status != GM_SUCCESS) {
111 fprintf(stderr, "gm_node_id_to_global_id(%s:%d): %s\n",
112 name, local_id, gm_strerror(gm_status));
116 if (name_fieldlen > 0)
117 printf ("%*s ", name_fieldlen, name);
120 printf("0x%x\n", global_id);
122 printf("local 0x%x global 0x%x\n", local_id, global_id);
133 main (int argc, char **argv)
139 int show_local_id = 0;
141 while ((c = getopt(argc, argv, "n:lLh")) != -1)
152 gmrc = print_gmid(optarg, 0, show_local_id);
153 return (gmrc == GM_SUCCESS) ? 0 : 1;
156 gmrc = print_gmid(NULL, 0, show_local_id);
157 return (gmrc == GM_SUCCESS) ? 0 : 1;
164 if (optind == argc) {
165 gmrc = print_gmid(NULL, 0, show_local_id);
166 return (gmrc == GM_SUCCESS) ? 0 : 1;
169 if (optind != argc - 1)
170 for (c = optind; c < argc; c++)
171 if (strlen(argv[c]) > max_namelen)
172 max_namelen = strlen(argv[c]);
176 for (c = optind; c < argc; c++) {
177 gmrc = print_gmid(argv[c], max_namelen, show_local_id);
179 if (gmrc != GM_SUCCESS)