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