Whamcloud - gitweb
* Landed portals:b_port_step as follows...
[fs/lustre-release.git] / lnet / utils / gmlndnid.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2   * vim:expandtab:shiftwidth=8:tabstop=8:
3   *
4   *  Copyright (c) 2003 Los Alamos National Laboratory (LANL)
5   *
6   *   This file is part of Lustre, http://www.lustre.org/
7   *
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.
11   *
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.
16   *
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.
20   */
21
22 #include <stdio.h>
23 #include <sys/types.h>
24 #include <sys/socket.h>
25 #include <netinet/tcp.h>
26 #include <netdb.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <fcntl.h>
30 #include <sys/ioctl.h>
31 #include <unistd.h>
32 #include <syslog.h>
33 #include <errno.h>
34
35 #include <portals/api-support.h>
36 #include <portals/lib-types.h>
37
38 #define GMNAL_IOC_GET_GNID 1
39
40 int main(int argc, char **argv)
41 {
42         int rc, pfd;
43         struct portal_ioctl_data data;
44         struct portals_cfg pcfg;
45         unsigned int    nid = 0, len;
46         char    *name = NULL;
47         int     c;
48
49
50
51         while ((c = getopt(argc, argv, "n:l")) != -1) {
52                 switch(c) {
53                 case('n'):
54                         name = optarg;  
55                 break;
56                 case('l'):
57                         printf("Get local id not implemented yet!\n");
58                         exit(-1);
59                 default:
60                         printf("usage %s -n nodename [-p]\n", argv[0]);
61                 }
62         }
63
64         if (!name) {
65                 printf("usage %s -n nodename [-p]\n", argv[0]);
66                 exit(-1);
67         }
68
69
70
71
72         PCFG_INIT(pcfg, GMNAL_IOC_GET_GNID);
73         pcfg.pcfg_nal = GMNAL;
74
75         /*
76          *      set up the inputs
77          */
78         len = strlen(name) + 1;
79         pcfg.pcfg_pbuf1 = malloc(len);
80         strcpy(pcfg.pcfg_pbuf1, name);
81         pcfg.pcfg_plen1 = len;
82
83         /*
84          *      set up the outputs
85          */
86         pcfg.pcfg_pbuf2 = (void*)&nid;
87         pcfg.pcfg_plen2 = sizeof(unsigned int*);
88
89         pfd = open("/dev/portals", O_RDWR);
90         if ( pfd < 0 ) {
91                 perror("opening portals device");
92                 free(pcfg.pcfg_pbuf1);
93                 exit(-1);
94         }
95
96         PORTAL_IOC_INIT(data);
97         data.ioc_pbuf1 = (char*)&pcfg;
98         data.ioc_plen1 = sizeof(pcfg);
99                 
100         rc = ioctl (pfd, IOC_PORTAL_NAL_CMD, &data);
101         if (rc < 0)
102         {
103                 perror ("Can't get my NID");
104         }
105                         
106         free(pcfg.pcfg_pbuf1);
107         close(pfd);
108         printf("%u\n", nid);
109         exit(0);
110 }