X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lnet%2Futils%2Fgmlndnid.c;h=340c8b92ebb248e3cd3af3d5408456a23a944364;hb=6934a910b6e1f1c6527f352d51f8f94e3758c793;hp=ff6631ce998cce7949ff2764fbde264efebf4ade;hpb=090c677210ee2946d99c71412e4ff762bb300f4f;p=fs%2Flustre-release.git diff --git a/lnet/utils/gmlndnid.c b/lnet/utils/gmlndnid.c index ff6631c..340c8b9 100644 --- a/lnet/utils/gmlndnid.c +++ b/lnet/utils/gmlndnid.c @@ -1,23 +1,40 @@ /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: - * - * Copyright (c) 2003 Los Alamos National Laboratory (LANL) - * - * This file is part of Lustre, http://www.lustre.org/ - * - * This file is free software; you can redistribute it and/or - * modify it under the terms of version 2.1 of the GNU Lesser General - * Public License as published by the Free Software Foundation. - * - * Lustre is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Portals; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ + * vim:expandtab:shiftwidth=8:tabstop=8: + * + * GPL HEADER START + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License version 2 for more details (a copy is included + * in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU General Public License + * version 2 along with this program; If not, see + * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + * GPL HEADER END + */ +/* + * Copyright 2008 Sun Microsystems, Inc. All rights reserved + * Use is subject to license terms. + * + * Copyright (c) 2003 Los Alamos National Laboratory (LANL) + */ +/* + * This file is part of Lustre, http://www.lustre.org/ + * Lustre is a trademark of Sun Microsystems, Inc. + */ #include #include @@ -29,91 +46,156 @@ #include #include #include -#include #include - #include -#include -#include -#include +#include +#include -#define GMNAL_IOC_GET_GNID 1 +#include -int -roundup(int len) +/* + * portals always uses unit 0 + * Can this be configurable? + */ +#define GM_UNIT 0 + +void +usage(char *prg, int h) +{ + fprintf(stderr, + "usage %s -h\n" + " %s [-l] [-n hostname] [-L] [hostnames]\n", prg); + + if (h) + printf("Print Myrinet Global network ids for specified hosts\n" + "-l print local host's ID\n" + "-n hostname print given host's ID\n" + "-L print Myringet local net ID too\n" + "[hostnames] print ids of given hosts (local if none)\n"); +} + +gm_status_t +print_gmid(char *name, int name_fieldlen, int show_local_id) { - return((len+7) & (~0x7)); + struct gm_port *gm_port; + int gm_port_id; + gm_status_t gm_status; + unsigned int local_id; + unsigned int global_id; + + gm_status = gm_init(); + if (gm_status != GM_SUCCESS) { + fprintf(stderr, "gm_init: %s\n", gm_strerror(gm_status)); + return gm_status; + } + + gm_port_id = 2; + gm_status = gm_open(&gm_port, GM_UNIT, gm_port_id, "gmnalnid", + GM_API_VERSION); + if (gm_status != GM_SUCCESS) { + int num_ports = gm_num_ports(gm_port); + + /* Couldn't open port 2, try 4 ... num_ports */ + for (gm_port_id = 4; gm_port_id < num_ports; gm_port_id++) { + gm_status = gm_open(&gm_port, GM_UNIT, gm_port_id, + "gmnalnid", GM_API_VERSION); + if (gm_status == GM_SUCCESS) + break; + } + + if (gm_status != GM_SUCCESS) { + fprintf(stderr, "gm_open: %s\n",gm_strerror(gm_status)); + goto out_0; + } + } + + if (name == NULL) { + local_id = 1; + name = ""; + } else { + gm_status = gm_host_name_to_node_id_ex(gm_port, 1000000, name, + &local_id); + if (gm_status != GM_SUCCESS) { + fprintf(stderr, "gm_host_name_to_node_id_ex(%s): %s\n", + name, gm_strerror(gm_status)); + goto out_1; + } + } + + gm_status = gm_node_id_to_global_id(gm_port, local_id, &global_id) ; + if (gm_status != GM_SUCCESS) { + fprintf(stderr, "gm_node_id_to_global_id(%s:%d): %s\n", + name, local_id, gm_strerror(gm_status)); + goto out_1; + } + + if (name_fieldlen > 0) + printf ("%*s ", name_fieldlen, name); + + if (!show_local_id) + printf("0x%x\n", global_id); + else + printf("local 0x%x global 0x%x\n", local_id, global_id); + + out_1: + gm_close(gm_port); + out_0: + gm_finalize(); + + return gm_status; } -int main(int argc, char **argv) +int +main (int argc, char **argv) { - int rc, pfd; - struct portal_ioctl_data data; - struct portals_cfg pcfg; - unsigned int nid = 0, len; - char *name = NULL; - int c; - - - - while ((c = getopt(argc, argv, "n:l")) != -1) { - switch(c) { - case('n'): - name = optarg; - break; - case('l'): - printf("Get local id not implemented yet!\n"); - exit(-1); - default: - printf("usage %s -n nodename [-p]\n", argv[0]); - } - } - - if (!name) { - printf("usage %s -n nodename [-p]\n", argv[0]); - exit(-1); - } - - - - - PCFG_INIT(pcfg, GMNAL_IOC_GET_GNID); - pcfg.pcfg_nal = GMNAL; - - /* - * set up the inputs - */ - len = strlen(name) + 1; - pcfg.pcfg_pbuf1 = malloc(len); - strcpy(pcfg.pcfg_pbuf1, name); - pcfg.pcfg_plen1 = len; - - /* - * set up the outputs - */ - pcfg.pcfg_pbuf2 = (void*)&nid; - pcfg.pcfg_plen2 = sizeof(unsigned int*); - - pfd = open("/dev/portals", O_RDWR); - if ( pfd < 0 ) { - perror("opening portals device"); - free(pcfg.pcfg_pbuf1); - exit(-1); + int c; + gm_status_t gmrc; + int rc; + int max_namelen = 0; + int show_local_id = 0; + + while ((c = getopt(argc, argv, "n:lLh")) != -1) + switch(c) { + case 'h': + usage(argv[0], 1); + return 0; + + case 'L': + show_local_id = 1; + break; + + case 'n': + gmrc = print_gmid(optarg, 0, show_local_id); + return (gmrc == GM_SUCCESS) ? 0 : 1; + + case 'l': + gmrc = print_gmid(NULL, 0, show_local_id); + return (gmrc == GM_SUCCESS) ? 0 : 1; + + default: + usage(argv[0], 0); + return 2; + } + + if (optind == argc) { + gmrc = print_gmid(NULL, 0, show_local_id); + return (gmrc == GM_SUCCESS) ? 0 : 1; } - PORTAL_IOC_INIT(data); - data.ioc_pbuf1 = (char*)&pcfg; - data.ioc_plen1 = sizeof(pcfg); - - rc = ioctl (pfd, IOC_PORTAL_NAL_CMD, &data); - if (rc < 0) - { - perror ("Can't get my NID"); + if (optind != argc - 1) + for (c = optind; c < argc; c++) + if (strlen(argv[c]) > max_namelen) + max_namelen = strlen(argv[c]); + + rc = 0; + + for (c = optind; c < argc; c++) { + gmrc = print_gmid(argv[c], max_namelen, show_local_id); + + if (gmrc != GM_SUCCESS) + rc = 1; } - - free(pcfg.pcfg_pbuf1); - close(pfd); - printf("%u\n", nid); - exit(0); + + return rc; }