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)
5 * Copyright (C) 2005 Cluster File Systems, Inc. All rights reserved.
7 * This file is part of Lustre, http://www.lustre.org/
9 * This file is free software; you can redistribute it and/or
10 * modify it under the terms of version 2.1 of the GNU Lesser General
11 * Public License as published by the Free Software Foundation.
13 * Lustre is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with Portals; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <sys/types.h>
25 #include <sys/socket.h>
26 #include <netinet/tcp.h>
31 #include <sys/ioctl.h>
36 #include <lnet/api-support.h>
37 #include <lnet/lib-types.h>
42 * portals always uses unit 0
43 * Can this be configurable?
48 usage(char *prg, int h)
52 " %s [-l] [-n hostname] [-L] [hostnames]\n", prg);
55 printf("Print Myrinet Global network ids for specified hosts\n"
56 "-l print local host's ID\n"
57 "-n hostname print given host's ID\n"
58 "-L print Myringet local net ID too\n"
59 "[hostnames] print ids of given hosts (local if none)\n");
63 print_gmid(char *name, int name_fieldlen, int show_local_id)
65 struct gm_port *gm_port;
67 gm_status_t gm_status;
68 unsigned int local_id;
69 unsigned int global_id;
71 gm_status = gm_init();
72 if (gm_status != GM_SUCCESS) {
73 fprintf(stderr, "gm_init: %s\n", gm_strerror(gm_status));
78 gm_status = gm_open(&gm_port, GM_UNIT, gm_port_id, "gmnalnid",
80 if (gm_status != GM_SUCCESS) {
81 int num_ports = gm_num_ports(gm_port);
83 /* Couldn't open port 2, try 4 ... num_ports */
84 for (gm_port_id = 4; gm_port_id < num_ports; gm_port_id++) {
85 gm_status = gm_open(&gm_port, GM_UNIT, gm_port_id,
86 "gmnalnid", GM_API_VERSION);
87 if (gm_status == GM_SUCCESS)
91 if (gm_status != GM_SUCCESS) {
92 fprintf(stderr, "gm_open: %s\n",gm_strerror(gm_status));
101 gm_status = gm_host_name_to_node_id_ex(gm_port, 1000000, name,
103 if (gm_status != GM_SUCCESS) {
104 fprintf(stderr, "gm_host_name_to_node_id_ex(%s): %s\n",
105 name, gm_strerror(gm_status));
110 gm_status = gm_node_id_to_global_id(gm_port, local_id, &global_id) ;
111 if (gm_status != GM_SUCCESS) {
112 fprintf(stderr, "gm_node_id_to_global_id(%s:%d): %s\n",
113 name, local_id, gm_strerror(gm_status));
117 if (name_fieldlen > 0)
118 printf ("%*s ", name_fieldlen, name);
121 printf("0x%x\n", global_id);
123 printf("local 0x%x global 0x%x\n", local_id, global_id);
134 main (int argc, char **argv)
140 int show_local_id = 0;
142 while ((c = getopt(argc, argv, "n:lLh")) != -1)
153 gmrc = print_gmid(optarg, 0, show_local_id);
154 return (gmrc == GM_SUCCESS) ? 0 : 1;
157 gmrc = print_gmid(NULL, 0, show_local_id);
158 return (gmrc == GM_SUCCESS) ? 0 : 1;
165 if (optind == argc) {
166 gmrc = print_gmid(NULL, 0, show_local_id);
167 return (gmrc == GM_SUCCESS) ? 0 : 1;
170 if (optind != argc - 1)
171 for (c = optind; c < argc; c++)
172 if (strlen(argv[c]) > max_namelen)
173 max_namelen = strlen(argv[c]);
177 for (c = optind; c < argc; c++) {
178 gmrc = print_gmid(argv[c], max_namelen, show_local_id);
180 if (gmrc != GM_SUCCESS)