Whamcloud - gitweb
ff6631ce998cce7949ff2764fbde264efebf4ade
[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 <asm/byteorder.h>
33 #include <syslog.h>
34
35 #include <errno.h>
36
37 #include <portals/api-support.h>
38 #include <portals/list.h>
39 #include <portals/lib-types.h>
40
41 #define GMNAL_IOC_GET_GNID 1
42
43 int
44 roundup(int len)
45 {
46         return((len+7) & (~0x7));
47 }
48
49 int main(int argc, char **argv)
50 {
51         int rc, pfd;
52         struct portal_ioctl_data data;
53         struct portals_cfg pcfg;
54         unsigned int    nid = 0, len;
55         char    *name = NULL;
56         int     c;
57
58
59
60         while ((c = getopt(argc, argv, "n:l")) != -1) {
61                 switch(c) {
62                 case('n'):
63                         name = optarg;  
64                 break;
65                 case('l'):
66                         printf("Get local id not implemented yet!\n");
67                         exit(-1);
68                 default:
69                         printf("usage %s -n nodename [-p]\n", argv[0]);
70                 }
71         }
72
73         if (!name) {
74                 printf("usage %s -n nodename [-p]\n", argv[0]);
75                 exit(-1);
76         }
77
78
79
80
81         PCFG_INIT(pcfg, GMNAL_IOC_GET_GNID);
82         pcfg.pcfg_nal = GMNAL;
83
84         /*
85          *      set up the inputs
86          */
87         len = strlen(name) + 1;
88         pcfg.pcfg_pbuf1 = malloc(len);
89         strcpy(pcfg.pcfg_pbuf1, name);
90         pcfg.pcfg_plen1 = len;
91
92         /*
93          *      set up the outputs
94          */
95         pcfg.pcfg_pbuf2 = (void*)&nid;
96         pcfg.pcfg_plen2 = sizeof(unsigned int*);
97
98         pfd = open("/dev/portals", O_RDWR);
99         if ( pfd < 0 ) {
100                 perror("opening portals device");
101                 free(pcfg.pcfg_pbuf1);
102                 exit(-1);
103         }
104
105         PORTAL_IOC_INIT(data);
106         data.ioc_pbuf1 = (char*)&pcfg;
107         data.ioc_plen1 = sizeof(pcfg);
108                 
109         rc = ioctl (pfd, IOC_PORTAL_NAL_CMD, &data);
110         if (rc < 0)
111         {
112                 perror ("Can't get my NID");
113         }
114                         
115         free(pcfg.pcfg_pbuf1);
116         close(pfd);
117         printf("%u\n", nid);
118         exit(0);
119 }